commit 9d8313365389ee71cb49fa193ed37a4d520de0ed
parent b4436e24181054e245ed5a570fea5dfc4c9e1232
Author: Michael Camilleri <[email protected]>
Date: Thu, 22 Oct 2026 01:26:28 +0900
Add script to publish to App Store Connect
Diffstat
| A | Scripts/publish-ios.sh | | | 192 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 192 insertions(+), 0 deletions(-)
diff --git a/Scripts/publish-ios.sh b/Scripts/publish-ios.sh
@@ -0,0 +1,192 @@
+#!/bin/bash
+set -euo pipefail
+
+REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+SECRETS="$REPO_ROOT/.asc/secrets.sh"
+
+if [[ ! -f "$SECRETS" ]]; then
+ echo "Error: $SECRETS not found. Copy .asc/ from another app; it holds team-wide signing files."
+ exit 1
+fi
+
+source "$SECRETS"
+
+SCHEME="Reportage"
+# Archive into the Xcode Archives library at a unique per-build path so
+# Organizer indexes every build and TestFlight crashes symbolicate
+# automatically. One timestamp drives both the date dir and the archive name
+# so they can't disagree across a midnight boundary.
+ARCHIVE_STAMP="$(date '+%Y-%m-%d %H.%M.%S')"
+ARCHIVE_DIR="$HOME/Library/Developer/Xcode/Archives/${ARCHIVE_STAMP%% *}"
+ARCHIVE_PATH="$ARCHIVE_DIR/$SCHEME $ARCHIVE_STAMP.xcarchive"
+EXPORT_PATH="/tmp/Reportage-export"
+EXPORT_PLIST="/tmp/Reportage-ExportOptions.plist"
+IPA_PATH="$EXPORT_PATH/Reportage.ipa"
+DEV_P12="$REPO_ROOT/.asc/dev.p12"
+DIST_P12="$REPO_ROOT/.asc/ios-signing/dist-headless.p12"
+TMP_KEYCHAIN="$REPO_ROOT/.asc/build.keychain-db"
+
+CHECK_ONLY=false
+if [[ "${1:-}" == "--check" ]]; then
+ CHECK_ONLY=true
+fi
+
+cd "$REPO_ROOT"
+
+if ! git diff --quiet || ! git diff --cached --quiet; then
+ echo "Error: Git repository is dirty. Commit or stash changes before publishing."
+ exit 1
+fi
+
+# A release tag marks a version as shipped. Uploading under a tagged version
+# means the bump after that release was missed, and the build would be rejected
+# by App Store Connect or land on a version already in the store.
+APP_VERSION="$(awk -F'"' '/CFBundleShortVersionString/ { print $2; exit }' "$REPO_ROOT/project.yml")"
+if [[ -z "$APP_VERSION" ]]; then
+ echo "Error: could not read CFBundleShortVersionString from project.yml."
+ exit 1
+fi
+if git rev-parse -q --verify "refs/tags/v$APP_VERSION" >/dev/null; then
+ echo "Error: v$APP_VERSION is already tagged as released. Bump the version in project.yml and both Info.plist files first."
+ exit 1
+fi
+
+# Capture the caller's exact keychain configuration before touching anything,
+# so cleanup restores their real prior state rather than assuming login-only.
+# `security` prints each path quoted and indented; strip both.
+unquote_keychain_path() {
+ local line="$1"
+ line="${line#"${line%%[![:space:]]*}"}"
+ line="${line%\"}"
+ line="${line#\"}"
+ printf '%s' "$line"
+}
+
+ORIGINAL_KEYCHAINS=()
+while IFS= read -r line; do
+ [[ -n "$line" ]] && ORIGINAL_KEYCHAINS+=("$(unquote_keychain_path "$line")")
+done < <(security list-keychains -d user)
+
+ORIGINAL_DEFAULT_KEYCHAIN="$(unquote_keychain_path "$(security default-keychain -d user 2>/dev/null || true)")"
+
+if [[ ${#ORIGINAL_KEYCHAINS[@]} -eq 0 ]]; then
+ echo "Error: could not read the current keychain search list; refusing to modify it."
+ exit 1
+fi
+
+# Cleanup must tolerate a partially completed setup: it is installed before the
+# temporary keychain exists, and any step below can die under `set -e`.
+cleanup_keychain() {
+ echo "==> Restoring keychain search list..."
+ if [[ ${#ORIGINAL_KEYCHAINS[@]} -gt 0 ]]; then
+ security list-keychains -d user -s "${ORIGINAL_KEYCHAINS[@]}" || true
+ fi
+ if [[ -n "$ORIGINAL_DEFAULT_KEYCHAIN" ]]; then
+ security default-keychain -d user -s "$ORIGINAL_DEFAULT_KEYCHAIN" || true
+ fi
+ security delete-keychain "$TMP_KEYCHAIN" 2>/dev/null || true
+ rm -f "$REPO_ROOT/private_keys/AuthKey_${KEY_ID}.p8"
+ rmdir "$REPO_ROOT/private_keys" 2>/dev/null || true
+}
+trap cleanup_keychain EXIT
+
+echo "==> Setting up temporary keychain..."
+security delete-keychain "$TMP_KEYCHAIN" 2>/dev/null || true
+security create-keychain -p "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
+security unlock-keychain -p "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
+security set-keychain-settings -lut 21600 "$TMP_KEYCHAIN"
+security import "$DEV_P12" -k "$TMP_KEYCHAIN" -P "$DEV_P12_PASS" \
+ -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild
+security import "$DIST_P12" -k "$TMP_KEYCHAIN" -P "$DIST_P12_PASS" \
+ -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild
+security set-key-partition-list -S apple-tool:,apple:,codesign:,productbuild: \
+ -s -k "$TMP_KEYCHAIN_PASS" "$TMP_KEYCHAIN"
+security list-keychains -d user -s "$TMP_KEYCHAIN" "${ORIGINAL_KEYCHAINS[@]}"
+
+mkdir -p "$ARCHIVE_DIR"
+echo "==> Archiving $SCHEME to $ARCHIVE_PATH..."
+xcodebuild \
+ -scheme "$SCHEME" \
+ -project Reportage.xcodeproj \
+ -configuration Release \
+ -destination 'generic/platform=iOS' \
+ -archivePath "$ARCHIVE_PATH" \
+ archive
+
+echo "==> Writing export options..."
+cat > "$EXPORT_PLIST" <<PLIST
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>method</key>
+ <string>app-store-connect</string>
+ <key>signingStyle</key>
+ <string>manual</string>
+ <key>teamID</key>
+ <string>$TEAM_ID</string>
+ <key>signingCertificate</key>
+ <string>iPhone Distribution</string>
+ <key>provisioningProfiles</key>
+ <dict>
+ <key>net.inqk.reportage</key>
+ <string>Reportage iOS Distribution</string>
+ <key>net.inqk.reportage.widgets</key>
+ <string>Reportage Widgets iOS Distribution</string>
+ </dict>
+ <key>destination</key>
+ <string>export</string>
+ <key>stripSwiftSymbols</key>
+ <true/>
+ <key>manageAppVersionAndBuildNumber</key>
+ <false/>
+</dict>
+</plist>
+PLIST
+
+echo "==> Exporting IPA..."
+xcodebuild \
+ -exportArchive \
+ -archivePath "$ARCHIVE_PATH" \
+ -exportPath "$EXPORT_PATH" \
+ -exportOptionsPlist "$EXPORT_PLIST"
+
+echo "==> Checking entitlements in exported IPA..."
+CHECK_DIR="/tmp/Reportage-ipa-check"
+rm -rf "$CHECK_DIR"
+unzip -q "$IPA_PATH" -d "$CHECK_DIR"
+APP_DIR="$CHECK_DIR/Payload/Reportage.app"
+APP_ENTITLEMENTS="$(codesign -d --entitlements - --xml "$APP_DIR" 2>/dev/null)"
+for key in com.apple.developer.healthkit com.apple.developer.weatherkit; do
+ if ! grep -q "<key>$key</key>" <<<"$APP_ENTITLEMENTS"; then
+ echo "Error: exported app is missing the $key entitlement."
+ exit 1
+ fi
+done
+if [[ ! -d "$APP_DIR/PlugIns/ReportageWidgets.appex" ]]; then
+ echo "Error: exported app does not contain ReportageWidgets.appex."
+ exit 1
+fi
+echo "--- iOS app entitlements ---"
+codesign -d --entitlements - "$APP_DIR"
+echo "--- Widgets entitlements ---"
+codesign -d --entitlements - "$APP_DIR/PlugIns/ReportageWidgets.appex"
+rm -rf "$CHECK_DIR"
+
+if $CHECK_ONLY; then
+ echo "==> Check complete. Skipping upload."
+ exit 0
+fi
+
+echo "==> Uploading to App Store Connect..."
+mkdir -p "$REPO_ROOT/private_keys"
+cp "$REPO_ROOT/.asc/AuthKey_${KEY_ID}.p8" "$REPO_ROOT/private_keys/"
+xcrun iTMSTransporter \
+ -m upload \
+ -assetFile "$IPA_PATH" \
+ -apiKey "$KEY_ID" \
+ -apiIssuer "$ISSUER_ID" \
+ -v informational
+
+echo "==> Done!"