Repository Public
1#!/bin/bash2# Release build of the iOS app for App Store Connect / TestFlight (team 3YM54G49SN).3# Scripts/release.sh archive Release archive + IPA signed for App Store distribution → dist/ios/4# Scripts/release.sh verify checks the IPA (signature, profile, entitlements, no Debug-only code, no ATS exception)5# Scripts/release.sh upload uploads the IPA to App Store Connect (TestFlight); refuses if the app record is missing6# Scripts/release.sh all archive + verify + upload7# Credentials (never stored in the repository, never printed):8# ASC_KEY_ID (default L379BDKR69), ASC_ISSUER_ID (required), ASC_KEY_PATH (default ~/.appstoreconnect/private_keys/AuthKey_<id>.p8)9# Signing is Xcode automatic signing authenticated by that API key (-allowProvisioningUpdates): Xcode creates or reuses10# the cloud-managed Apple Distribution certificate and the App Store profile of ai.spboucher.clustr.ios. Bundle ids and11# capabilities are registered beforehand by `infra/apple/provision.py --ios`.12# Environment: MCC_DERIVED_DATA (default /tmp/mcc-ios/ReleaseDerivedData — keep it OUTSIDE ~/Desktop), MCC_BUILD_NUMBER.13set -euo pipefail14cd "$(dirname "$0")/.."15ROOT="$PWD"16REPO="$(cd ../.. && pwd)"17MODE="${1:-}"18DD="${MCC_DERIVED_DATA:-/tmp/mcc-ios/ReleaseDerivedData}"19PROJ="$DD.project"20BUNDLE_ID="ai.spboucher.clustr.ios"21TEAM="3YM54G49SN"22VERSION="$(sed -n 's/^ *MARKETING_VERSION: *"\(.*\)"/\1/p' project.yml | head -1)"23BUILD="${MCC_BUILD_NUMBER:-$(sed -n 's/^ *CURRENT_PROJECT_VERSION: *"\(.*\)"/\1/p' project.yml | head -1)}"24OUT="$REPO/dist/ios"25ARCHIVE="$DD/MacLustr-$VERSION-$BUILD.xcarchive"26IPA="${MCC_IPA:-$OUT/MacLustr-CC-$VERSION-$BUILD.ipa}"2728creds() {29 export ASC_KEY_ID="${ASC_KEY_ID:-L379BDKR69}"30 : "${ASC_ISSUER_ID:?set ASC_ISSUER_ID (App Store Connect issuer id)}"31 ASC_KEY_PATH="${ASC_KEY_PATH:-$HOME/.appstoreconnect/private_keys/AuthKey_$ASC_KEY_ID.p8}"32 [ -f "$ASC_KEY_PATH" ] || { echo "API key file not found for key $ASC_KEY_ID" >&2; exit 1; }33 AUTH=(-allowProvisioningUpdates -authenticationKeyPath "$ASC_KEY_PATH" -authenticationKeyID "$ASC_KEY_ID" -authenticationKeyIssuerID "$ASC_ISSUER_ID")34}3536archive() {37 creds38 mkdir -p "$PROJ" "$OUT"39 xcodegen generate --quiet --spec project.yml --project "$PROJ" --project-root .40 rm -rf "$ARCHIVE" "$DD/export"41 echo "== archive $VERSION ($BUILD)"42 xcodebuild -project "$PROJ/MCCiOS.xcodeproj" -scheme MCCiOS -configuration Release -derivedDataPath "$DD" \43 -destination 'generic/platform=iOS' -archivePath "$ARCHIVE" -skipPackagePluginValidation -skipMacroValidation \44 MCC_ROOT="$ROOT" CURRENT_PROJECT_VERSION="$BUILD" "${AUTH[@]}" archive > "$DD.archive.log" 2>&1 \45 || { grep -E "error:|\*\* ARCHIVE" "$DD.archive.log" | sort -u | tail -30; exit 1; }46 grep -E "\*\* ARCHIVE" "$DD.archive.log"47 cat > "$DD/ExportOptions.plist" <<PLIST48<?xml version="1.0" encoding="UTF-8"?>49<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">50<plist version="1.0">51<dict>52 <key>method</key><string>app-store-connect</string>53 <key>destination</key><string>export</string>54 <key>teamID</key><string>$TEAM</string>55 <key>signingStyle</key><string>automatic</string>56 <key>manageAppVersionAndBuildNumber</key><false/>57 <key>uploadSymbols</key><true/>58 <key>stripSwiftSymbols</key><true/>59</dict>60</plist>61PLIST62 echo "== export (App Store distribution signature)"63 xcodebuild -exportArchive -archivePath "$ARCHIVE" -exportPath "$DD/export" -exportOptionsPlist "$DD/ExportOptions.plist" "${AUTH[@]}" > "$DD.export.log" 2>&1 \64 || { grep -E "error:|Error|\*\* EXPORT" "$DD.export.log" | sort -u | tail -30; exit 1; }65 grep -E "\*\* EXPORT" "$DD.export.log"66 local produced67 produced="$(ls "$DD/export"/*.ipa | head -1)"68 cp "$produced" "$IPA"69 shasum -a 256 "$IPA" | tee "$IPA.sha256"70 echo "$IPA"71}7273verify() {74 [ -f "$IPA" ] || { echo "no IPA at $IPA — run: Scripts/release.sh archive" >&2; exit 1; }75 local tmp app fail=076 tmp="$(mktemp -d /tmp/mcc-ios-verify.XXXXXX)"77 unzip -q "$IPA" -d "$tmp"78 app="$(ls -d "$tmp"/Payload/*.app | head -1)"79 check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; fail=1; fi; }80 codesign -d --entitlements :- "$app" > "$tmp/ent.plist" 2>/dev/null || true81 security cms -D -i "$app/embedded.mobileprovision" > "$tmp/profile.plist" 2>/dev/null || true82 codesign -dvv "$app" > "$tmp/sig.txt" 2>&1 || true83 strings -a "$app/MacLustr" > "$tmp/strings.txt"84 pl() { /usr/libexec/PlistBuddy -c "Print $2" "$1" 2>/dev/null; }85 has() { local out; out="$(pl "$1" "$2")" || return 1; case "$out" in *"$3"*) return 0 ;; *) return 1 ;; esac; }86 check "signature valid (codesign --verify --strict)" "codesign --verify --strict '$app' 2>/dev/null"87 check "signed by an Apple / iPhone Distribution certificate" "grep -Eq 'Authority=(Apple|iPhone) Distribution' '$tmp/sig.txt'"88 check "bundle id $BUNDLE_ID" "[ \"\$(pl '$app/Info.plist' :CFBundleIdentifier)\" = '$BUNDLE_ID' ]"89 check "version $VERSION ($BUILD)" "[ \"\$(pl '$app/Info.plist' :CFBundleShortVersionString)\" = '$VERSION' ] && [ \"\$(pl '$app/Info.plist' :CFBundleVersion)\" = '$BUILD' ]"90 check "display name MacLustr CC" "[ \"\$(pl '$app/Info.plist' :CFBundleDisplayName)\" = 'MacLustr CC' ]"91 check "ITSAppUsesNonExemptEncryption = NO" "[ \"\$(pl '$app/Info.plist' :ITSAppUsesNonExemptEncryption)\" = 'false' ]"92 check "NSFaceIDUsageDescription present" "[ -n \"\$(pl '$app/Info.plist' :NSFaceIDUsageDescription)\" ]"93 check "no ATS exception" "! pl '$app/Info.plist' :NSAppTransportSecurity >/dev/null"94 check "no custom URL scheme (Debug only)" "! pl '$app/Info.plist' :CFBundleURLTypes >/dev/null"95 check "application-identifier $TEAM.$BUNDLE_ID" "[ \"\$(pl '$tmp/ent.plist' :application-identifier)\" = '$TEAM.$BUNDLE_ID' ]"96 check "aps-environment production" "[ \"\$(pl '$tmp/ent.plist' :aps-environment)\" = 'production' ]"97 check "associated domains webcredentials + applinks" "has '$tmp/ent.plist' :com.apple.developer.associated-domains 'webcredentials:clustr.spboucher.ai' && has '$tmp/ent.plist' :com.apple.developer.associated-domains 'applinks:clustr.spboucher.ai'"98 check "keychain access group $TEAM.$BUNDLE_ID" "has '$tmp/ent.plist' :keychain-access-groups '$TEAM.$BUNDLE_ID'"99 check "get-task-allow absent or false" "[ \"\$(pl '$tmp/ent.plist' :get-task-allow)\" != 'true' ]"100 check "embedded profile: App Store (no devices), team $TEAM" "[ -s '$tmp/profile.plist' ] && ! pl '$tmp/profile.plist' :ProvisionedDevices >/dev/null && has '$tmp/profile.plist' :TeamIdentifier '$TEAM'"101 check "no Debug-only code (software authenticator, file secure store, launch overrides)" "[ -s '$tmp/strings.txt' ] && ! grep -Eq 'SoftwareAuthenticator|DebugFileSecureStore|MCC_BASE_URL|MCC_OPEN_URL|mcc-ios-debug' '$tmp/strings.txt'"102 check "app icon compiled" "[ -f '$app/Assets.car' ]"103 check "fr and en localizations" "[ -d '$app/fr.lproj' ] && [ -d '$app/en.lproj' ]"104 echo "profile: $(pl "$tmp/profile.plist" :Name) (expires $(pl "$tmp/profile.plist" :ExpirationDate))"105 rm -rf "$tmp"106 return $fail107}108109upload() {110 creds111 [ -f "$IPA" ] || { echo "no IPA at $IPA — run: Scripts/release.sh archive" >&2; exit 1; }112 # The app record cannot be created through the public API: check first, and stop with instructions if it is missing.113 local n114 n="$(cd "$REPO/infra/apple" && python3 -c "115import asc116s, d = asc.call('GET', '/v1/apps?filter[bundleId]=$BUNDLE_ID&limit=200')117print(sum(1 for a in d.get('data', []) if a['attributes'].get('bundleId') == '$BUNDLE_ID') if s == 200 else 'error %s' % s)")"118 if [ "$n" != 1 ]; then119 cat >&2 <<MSG120App Store Connect app record for $BUNDLE_ID: not found (query result: $n). Nothing was uploaded.121Create it in App Store Connect → Apps → + → New App:122 Platform: iOS · Name: MacLustr CC · Primary language: French (Canada) · Bundle ID: $BUNDLE_ID · SKU: maclustr-cc-ios-001123then run: Scripts/release.sh upload124MSG125 exit 3126 fi127 echo "== upload to App Store Connect"128 # altool looks for the key in ~/.appstoreconnect/private_keys by key id.129 xcrun altool --upload-app -f "$IPA" -t ios --apiKey "$ASC_KEY_ID" --apiIssuer "$ASC_ISSUER_ID" --output-format normal 2>&1 | tee "$DD.upload.log" | grep -v "^\s*$" | tail -30130 grep -Eq "No errors uploading|UPLOAD SUCCEEDED" "$DD.upload.log"131}132133case "$MODE" in134 archive) archive ;;135 verify) verify ;;136 upload) upload ;;137 all) archive; verify; upload ;;138 *) sed -n '2,6p' "$0"; exit 2 ;;139esac140