Open source CapCut alternative.
TypeScript
build(ios): TestFlight ships a commit, not the working tree
David Le4ff41f14a1a0
diff --git a/docs/guides/ios-app.md b/docs/guides/ios-app.mdindex aaf41065..797bad1e 100644--- a/docs/guides/ios-app.md+++ b/docs/guides/ios-app.md@@ -150,6 +150,12 @@ unattended runs (the variables are documented in the script header). Onceprocessing finishes, internal testers in App Store Connect → TestFlight getthe build without review.+A build that testers install has to be a build you can go back to, so the+archive is cut from a commit: the script checks the ref out into a worktree of+its own and builds there, and whatever else is uncommitted in the checkout+stays out of the upload. `--ref` picks the commit and `--working-tree`+archives the checkout as it stands, for trying a build before committing it.+Export compliance is answered in the project (`ITSAppUsesNonExemptEncryption`is NO) and the privacy manifest ships in the app target, so uploads landready to test.diff --git a/scripts/ship-ios-on-commit.sh b/scripts/ship-ios-on-commit.shnew file mode 100755index 00000000..3250824b--- /dev/null+++ b/scripts/ship-ios-on-commit.sh@@ -0,0 +1,58 @@+#!/usr/bin/env bash+# The body of the post-commit TestFlight hook (.claude/settings.local.json).+# Ships the newest commit that touches apps/ios, once, however many commits+# land in a burst: the first one takes the lock and keeps shipping until the+# branch stops moving, so a session that lands seven commits uploads the last+# of them instead of the first.+#+# Every build is cut from the commit itself, so uncommitted work in the+# checkout — a half-finished feature, another project's edits — never rides+# along to TestFlight.+#+# Exits 0 with no output when there is nothing to ship, and 2 to report a+# failed ship back to the session.+set -uo pipefail++ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"+cd "$ROOT" || exit 0++LOCK=/tmp/donkey-ship-ios.lock+LOG=dist/ship-ios.log+# The last commit that reached TestFlight, so re-running the hook re-ships+# nothing.+LAST=dist/.ship-ios-last+# A commit older than this came from something other than the command that+# just ran.+FRESH_SECONDS=600++head_sha() { git rev-parse HEAD 2>/dev/null; }+touches_ios() { [[ -n "$(git diff --name-only "$1" "$2" -- apps/ios)" ]]; }++sha="$(head_sha)" || exit 0+[[ -n "$sha" ]] || exit 0+[[ "$sha" != "$(cat "$LAST" 2>/dev/null)" ]] || exit 0+(( $(date +%s) - $(git log -1 --format=%ct "$sha") < FRESH_SECONDS )) || exit 0+[[ -n "$(git show --name-only --format= "$sha" -- apps/ios)" ]] || exit 0++# A ship already holds the lock; its loop picks this commit up on the way out.+mkdir "$LOCK" 2>/dev/null || exit 0+trap 'rmdir "$LOCK" 2>/dev/null' EXIT++mkdir -p dist+shipped=""+while :; do+ if [[ -n "$shipped" ]]; then+ sha="$(head_sha)" || break+ [[ "$sha" != "$shipped" ]] || break+ touches_ios "$shipped" "$sha" || break+ fi+ shipped="$sha"+ short="$(git rev-parse --short "$sha")"+ if scripts/ship-ios-testflight.sh --ref "$sha" >"$LOG" 2>&1; then+ printf '%s' "$sha" > "$LAST"+ echo "TestFlight upload done ($short)"+ else+ echo "TestFlight ship failed for $short; see $LOG" >&2+ exit 2+ fi+donediff --git a/scripts/ship-ios-testflight.sh b/scripts/ship-ios-testflight.shindex cb63b638..13331e25 100755--- a/scripts/ship-ios-testflight.sh+++ b/scripts/ship-ios-testflight.sh@@ -4,6 +4,14 @@# Settings → Accounts). Signing stays automatic; Xcode manages the build# number against App Store Connect so repeat uploads never collide.#+# scripts/ship-ios-testflight.sh [--ref <git-ref>] [--working-tree]+#+# A TestFlight build has to be reproducible, so the archive is cut from a+# committed tree: the script checks the ref out into its own worktree under+# dist/ and builds there, and uncommitted edits elsewhere in the repo stay out+# of it. --working-tree archives the checkout as it stands instead, for trying+# a build before committing it.+## Auth uses the Apple ID session stored by Xcode. To run unattended (CI),# provide an App Store Connect API key instead:# DONKEY_ASC_KEY_P8_PATH=/path/AuthKey_XXXX.p8@@ -14,9 +22,52 @@ set -euo pipefailROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"export DEVELOPER_DIR="${DEVELOPER_DIR:-/Applications/Xcode.app/Contents/Developer}"+# Build inputs git does not carry. The archive needs them copied into the+# checkout it builds from, or the app builds without its deployment ids.+LOCAL_INPUTS=(apps/ios/Config/Donkey.local.xcconfig)++REF="HEAD"+WORKING_TREE=0+while [[ $# -gt 0 ]]; do+ case "$1" in+ --ref) REF="${2:?--ref needs a git ref}"; shift 2 ;;+ --working-tree) WORKING_TREE=1; shift ;;+ -h|--help) sed -n '2,19p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;+ *) echo "Unknown option: $1" >&2; exit 2 ;;+ esac+done+ARCHIVE="$ROOT/dist/DonkeyIOS.xcarchive"+# One path for every ship, so Xcode's derived data stays warm between them.+SOURCE="$ROOT/dist/ios-src"+DERIVED="$ROOT/dist/ios-derived"EXPORT_PLIST="$(mktemp -t donkey-ios-export.XXXXXX).plist"-trap 'rm -f "$EXPORT_PLIST"' EXIT+CHECKED_OUT=0++cleanup() {+ rm -f "$EXPORT_PLIST"+ if (( CHECKED_OUT )); then+ git -C "$ROOT" worktree remove --force "$SOURCE" >/dev/null 2>&1 || rm -rf "$SOURCE"+ git -C "$ROOT" worktree prune >/dev/null 2>&1 || true+ fi+}+trap cleanup EXIT++if (( WORKING_TREE )); then+ BUILD_ROOT="$ROOT"+ echo "==> Building the working tree"+else+ SHA="$(git -C "$ROOT" rev-parse --verify "$REF^{commit}")"+ echo "==> Building $(git -C "$ROOT" log -1 --format='%h %s' "$SHA")"+ rm -rf "$SOURCE"+ git -C "$ROOT" worktree prune+ git -C "$ROOT" worktree add --detach --quiet "$SOURCE" "$SHA"+ CHECKED_OUT=1+ for input in "${LOCAL_INPUTS[@]}"; do+ [[ -f "$ROOT/$input" ]] && cp "$ROOT/$input" "$SOURCE/$input"+ done+ BUILD_ROOT="$SOURCE"+ficat > "$EXPORT_PLIST" <<'PLIST'<?xml version="1.0" encoding="UTF-8"?>@@ -47,11 +98,12 @@ fiecho "==> Archiving"rm -rf "$ARCHIVE"xcodebuild archive \- -project "$ROOT/apps/ios/Donkey.xcodeproj" \+ -project "$BUILD_ROOT/apps/ios/Donkey.xcodeproj" \-scheme Donkey \-configuration Release \-destination 'generic/platform=iOS' \-archivePath "$ARCHIVE" \+ -derivedDataPath "$DERIVED" \-allowProvisioningUpdates \${AUTH_ARGS[@]+"${AUTH_ARGS[@]}"} \-quiet