#!/usr/bin/env bash
# Archives the native Physarum app for iOS + tvOS and exports App Store .ipa packages.
#
# Output: dist-appstore/Physarum-iOS.xcarchive + dist-appstore/ios/*.ipa (and tvos/*.ipa).
# Requires: Xcode (xcodebuild), xcodegen, and an Apple account with App Store
# distribution enabled (Apple Distribution cert + App Store provisioning). The
# archive/export run with -allowProvisioningUpdates so Xcode can create the profile.
#
# The macOS Developer-ID DMG pipeline (build-macos-app.sh) is separate and untouched.
set -euo pipefail
cd "$(dirname "$0")/.."
SCHEME="Physarum"
TEAM_ID="U9X7M39R56"
PROJ_DIR="apple/PhysarumApp"
EXPORT_PLIST_ABS="$(pwd)/scripts/ExportOptions-appstore.plist"
OUT="dist-appstore"
for tool in xcodebuild xcodegen; do
command -v "$tool" >/dev/null 2>&1 || { echo "error: required tool not found: $tool" >&2; exit 1; }
done
[ -f "$EXPORT_PLIST_ABS" ] || { echo "error: missing $EXPORT_PLIST_ABS" >&2; exit 1; }
( cd "$PROJ_DIR" && xcodegen generate )
mkdir -p "$OUT"
archive_and_export() {
local platform="$1" tag="$2"
local archive="$OUT/Physarum-$tag.xcarchive"
echo "==> Archiving $tag ($platform)"
xcodebuild archive \
-project "$PROJ_DIR/Physarum.xcodeproj" \
-scheme "$SCHEME" \
-destination "generic/platform=$platform" \
-archivePath "$archive" \
-allowProvisioningUpdates \
DEVELOPMENT_TEAM="$TEAM_ID"
echo "==> Exporting $tag .ipa"
xcodebuild -exportArchive \
-archivePath "$archive" \
-exportOptionsPlist "$EXPORT_PLIST_ABS" \
-exportPath "$OUT/$tag" \
-allowProvisioningUpdates
}
archive_and_export "iOS" "ios"
archive_and_export "tvOS" "tvos"
echo "Done. Upload the .ipa(s) in $OUT/ via Xcode Organizer or 'xcrun altool/notarytool'/Transporter."