#!/bin/bash # PAILot App Store Build Script # Builds an iOS IPA and uploads it to App Store Connect. # Adapted from Glidr's pipeline — same Apple Dev Team (7KU642K5ZL). set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" APP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$APP_DIR" # App Store Connect API credentials (issuer is shared across keys for this team). ASC_KEY_ID="${ASC_KEY_ID:-4H68LK2M3J}" ASC_ISSUER_ID="${ASC_ISSUER_ID:-69a6de75-2050-47e3-e053-5b8c7c11a4d1}" ASC_KEY_PATH="${ASC_KEY_PATH:-$HOME/.appstoreconnect/private_keys/AuthKey_${ASC_KEY_ID}.p8}" TEAM_ID="7KU642K5ZL" if [ ! -f "$ASC_KEY_PATH" ]; then echo "ERROR: App Store Connect API key not found at $ASC_KEY_PATH" echo " Download from https://appstoreconnect.apple.com/access/api" exit 1 fi # Homebrew rsync breaks Xcode's export step — temporarily hide it. BREW_RSYNC="$(brew --prefix 2>/dev/null)/bin/rsync" RSYNC_MOVED=false if [ -f "$BREW_RSYNC" ]; then mv "$BREW_RSYNC" "${BREW_RSYNC}.bak" RSYNC_MOVED=true echo " Temporarily hid Homebrew rsync" fi cleanup() { if [ "$RSYNC_MOVED" = true ] && [ -f "${BREW_RSYNC}.bak" ]; then mv "${BREW_RSYNC}.bak" "$BREW_RSYNC" echo " Restored Homebrew rsync" fi } trap cleanup EXIT echo "=== Building IPA for App Store ===" flutter build ipa --release --export-method development --no-tree-shake-icons echo "" echo "=== Fixing archive name ===" ARCHIVE="build/ios/archive/Runner.xcarchive/Info.plist" if [ -f "$ARCHIVE" ]; then plutil -replace Name -string "PAILot" "$ARCHIVE" plutil -replace SchemeName -string "PAILot" "$ARCHIVE" echo " Archive name set to 'PAILot'" fi echo "" echo "=== Exporting and uploading to App Store Connect ===" cat > /tmp/PAILotAppStoreExport.plist < method app-store-connect destination upload signingStyle automatic teamID ${TEAM_ID} PLIST rm -rf /tmp/pailot-appstore-export 2>/dev/null xcodebuild -exportArchive \ -archivePath build/ios/archive/Runner.xcarchive \ -exportOptionsPlist /tmp/PAILotAppStoreExport.plist \ -exportPath /tmp/pailot-appstore-export \ -allowProvisioningUpdates \ -authenticationKeyPath "$ASC_KEY_PATH" \ -authenticationKeyID "$ASC_KEY_ID" \ -authenticationKeyIssuerID "$ASC_ISSUER_ID" echo "" echo "=== Done ===" echo "Uploaded to App Store Connect. Next: complete the build's metadata and submit for review."