|
| 1 | +#!/bin/bash |
| 2 | +# Archives the iOS app with the local Xcode and uploads it to App Store Connect. |
| 3 | +# Used while the GitHub runners lack the iOS 27.1 SDK, which iPhone Duo needs for full-screen apps. |
| 4 | +# usage: ASC_KEY_ID=... ASC_ISSUER_ID=... scripts/upload-ios.sh <build-number> [version] |
| 5 | +set -euo pipefail |
| 6 | +cd "$(dirname "$0")/.." |
| 7 | + |
| 8 | +build="${1:?usage: scripts/upload-ios.sh <build-number> [version]}" |
| 9 | +version="${2:-$(grep -m1 'MARKETING_VERSION' project.yml | awk '{print $2}')}" |
| 10 | +certs="${SPANSCREEN_CERTS:-$HOME/.apple-certs/spanscreen}" |
| 11 | +: "${ASC_KEY_ID:?}" "${ASC_ISSUER_ID:?}" |
| 12 | + |
| 13 | +sdk=$(xcrun --sdk iphoneos --show-sdk-version) |
| 14 | +if [ "$(printf '%s\n27.1\n' "$sdk" | sort -V | head -1)" != "27.1" ]; then |
| 15 | + echo "iOS SDK $sdk is older than 27.1" >&2 |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +tmp=$(mktemp -d) |
| 20 | +keychain="$tmp/signing.keychain-db" |
| 21 | +password=$(uuidgen) |
| 22 | +original=$(security list-keychains -d user | tr -d '"') |
| 23 | +cleanup() { |
| 24 | + security list-keychains -d user -s $original |
| 25 | + security delete-keychain "$keychain" 2>/dev/null || true |
| 26 | + rm -rf "$tmp" |
| 27 | +} |
| 28 | +trap cleanup EXIT |
| 29 | + |
| 30 | +security create-keychain -p "$password" "$keychain" |
| 31 | +security set-keychain-settings -lut 3600 "$keychain" |
| 32 | +security list-keychains -d user -s "$keychain" $original |
| 33 | +security unlock-keychain -p "$password" "$keychain" |
| 34 | +security import "$certs/dist.p12" -P "$(cat "$certs/p12.pass")" -A -f pkcs12 -k "$keychain" >/dev/null |
| 35 | +security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$password" "$keychain" >/dev/null |
| 36 | +identity=$(security find-identity -v -p codesigning "$keychain" | awk 'NR==1 {print $2}') |
| 37 | + |
| 38 | +profile="$certs/appstore.mobileprovision" |
| 39 | +uuid=$(security cms -D -i "$profile" | plutil -extract UUID raw -) |
| 40 | +team=$(security cms -D -i "$profile" | plutil -extract TeamIdentifier.0 raw -) |
| 41 | +mkdir -p "$HOME/Library/MobileDevice/Provisioning Profiles" |
| 42 | +cp "$profile" "$HOME/Library/MobileDevice/Provisioning Profiles/$uuid.mobileprovision" |
| 43 | + |
| 44 | +echo "Archiving Spanscreen $version ($build) with iOS SDK $sdk" |
| 45 | +xcodebuild archive -quiet \ |
| 46 | + -project Spanscreen.xcodeproj \ |
| 47 | + -scheme SpanscreenIOS \ |
| 48 | + -destination generic/platform=iOS \ |
| 49 | + -archivePath "$tmp/Spanscreen-ios.xcarchive" \ |
| 50 | + MARKETING_VERSION="$version" \ |
| 51 | + CURRENT_PROJECT_VERSION="$build" \ |
| 52 | + CODE_SIGN_STYLE=Manual \ |
| 53 | + CODE_SIGN_IDENTITY="$identity" \ |
| 54 | + PROVISIONING_PROFILE_SPECIFIER="$uuid" \ |
| 55 | + DEVELOPMENT_TEAM="$team" \ |
| 56 | + OTHER_CODE_SIGN_FLAGS="--keychain $keychain" |
| 57 | + |
| 58 | +sed -e "s/__TEAM__/$team/" -e "s/__PROFILE__/$uuid/" scripts/ExportOptions-ios.plist > "$tmp/ExportOptions.plist" |
| 59 | +plutil -replace signingCertificate -string "$identity" "$tmp/ExportOptions.plist" |
| 60 | +xcodebuild -exportArchive -quiet -archivePath "$tmp/Spanscreen-ios.xcarchive" -exportPath "$tmp/ios" -exportOptionsPlist "$tmp/ExportOptions.plist" |
| 61 | + |
| 62 | +xcrun altool --upload-app -f "$tmp/ios/Spanscreen.ipa" -t ios --apiKey "$ASC_KEY_ID" --apiIssuer "$ASC_ISSUER_ID" |
0 commit comments