#!/bin/sh # Base for the iPhone, to TestFlight: an archive of this checkout's commit, # signed for the App Store with Base's profile, exported and uploaded with # the App Store Connect key. A copy of agent-tools/equipo-tf/testflight.sh # with Base's paths, bundle ID and profile, and no widget extension. # # native/scripts/testflight.sh VERSION BUILD # the plan # native/scripts/testflight.sh VERSION BUILD --upload # do it # # The plan (the default) checks what it can without signing (a clean tree # at a pushed commit, the pinned Timeless Sans, xcodegen) and prints every # command. --upload runs them in a detached worktree of the commit: the # Apple Distribution identity, Base's App Store profile (PROFILE, by name) # and the App Store Connect record "Oficina Base" (Paul's portal steps) # must exist. The worktree is a fresh one under $TMPDIR, and only a # worktree this run made is removed when it's done (worktree-lib.sh). set -eu VERSION=${1:?usage: testflight.sh VERSION BUILD [--upload]} BUILD=${2:?usage: testflight.sh VERSION BUILD [--upload]} UPLOAD=0 case "${3:-}" in --upload) UPLOAD=1 ;; "") ;; *) echo "usage: testflight.sh VERSION BUILD [--upload]" >&2; exit 2 ;; esac NATIVE=$(cd "$(dirname "$0")/.." && pwd) REPO=$(dirname "$NATIVE") COMMIT=$(git -C "$REPO" rev-parse HEAD) TEAM=9U4A84C4WK PROFILE=${PROFILE:-Oficina Base iOS App Store 2026-11-23} KEYS=$HOME/private_keys/oficina run() { echo " + $*"; [ "$UPLOAD" = 0 ] || "$@"; } die() { echo "error: $*" >&2; exit 1; } [ "$UPLOAD" = 1 ] && echo "uploading Base $VERSION ($BUILD) from $COMMIT" || echo "the plan for Base $VERSION ($BUILD) from $COMMIT; --upload runs it" case "$BUILD" in ''|*[!0-9]*) die "BUILD is not a positive integer" ;; esac if [ -n "$(git -C "$REPO" status --porcelain)" ]; then [ "$UPLOAD" = 1 ] && die "$REPO has local changes" || echo " WARNING: local changes (--upload refuses them)" fi git -C "$REPO" branch -r --contains "$COMMIT" | grep -q . || { [ "$UPLOAD" = 1 ] && die "$COMMIT is on no remote branch" || echo " WARNING: $COMMIT is on no remote branch (--upload refuses it)"; } "$REPO/hack/fonts.sh" check command -v xcodegen >/dev/null || die "no xcodegen" if [ "$UPLOAD" = 1 ]; then CERT=$(shasum -a 1 < "$KEYS/distribution.cer" | cut -d' ' -f1 | tr a-f A-F) [ -f "$KEYS/AuthKey_94GGSRG3FH.p8" ] || die "no App Store Connect key" else CERT='' echo " checked only with --upload: the distribution identity, the App Store Connect key, profile '$PROFILE'" fi . "$NATIVE/scripts/worktree-lib.sh" trap 'own_worktree_cleanup "$REPO"' EXIT if [ "$UPLOAD" = 1 ]; then own_worktree_add "$REPO" "$COMMIT" "base-tf-$BUILD" || die "could not make a worktree of $COMMIT" WT=$OWN_WT echo " + git worktree add --detach $WT $COMMIT" else WT='$TMPDIR/base-tf-'$BUILD'.XXXXXX' echo " + git worktree add --detach $WT $COMMIT (a fresh directory; only it is removed after)" fi # The font is fetched, never committed: the worktree gets its own copy. run mkdir -p "$WT/internal/look/static/fonts/timeless/1.094" run cp "$REPO/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2" "$WT/internal/look/static/fonts/timeless/1.094/" run "$WT/native/scripts/fonts-into-bundle.sh" --release # The build's own scratch, fresh: never a directory someone else left. if [ "$UPLOAD" = 1 ]; then OUT=$(mktemp -d "${TMPDIR:-/tmp}/base-tf-build-$BUILD.XXXXXX"); else OUT='$TMPDIR/base-tf-build-'$BUILD'.XXXXXX'; fi run xcodegen generate --quiet --spec "$WT/native/ios/project.yml" run xcodebuild archive -project "$WT/native/ios/BasePhone.xcodeproj" -scheme BasePhone -destination generic/platform=iOS \ -derivedDataPath "$OUT/derived" -archivePath "$OUT/BasePhone.xcarchive" \ DEVELOPMENT_TEAM=$TEAM MARKETING_VERSION="$VERSION" CURRENT_PROJECT_VERSION="$BUILD" CODE_SIGN_STYLE=Manual \ CODE_SIGN_IDENTITY="$CERT" "OFICINA_PROVISIONING_PROFILE=$PROFILE" if [ "$UPLOAD" = 1 ]; then APP=$(ls -d "$OUT/BasePhone.xcarchive/Products/Applications/"*.app) codesign --verify --deep --strict "$APP" /usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" -c "Print :CFBundleVersion" -c "Print :ITSAppUsesNonExemptEncryption" "$APP/Info.plist" ls "$APP"/BaseNative_BaseKit.bundle/Fonts/TimelessSansVF.woff2 >/dev/null || die "Timeless Sans is not in the app" cat > "$OUT/ExportOptions.plist" < methodapp-store-connectteamID$TEAM signingStylemanualsigningCertificate$CERT provisioningProfilesworks.oficina.base$PROFILE destinationuploadmanageAppVersionAndBuildNumber PL else echo " (checks the archive's signature, bundle ID, build, export compliance and Timeless Sans; writes ExportOptions.plist for works.oficina.base)" fi run xcodebuild -exportArchive -archivePath "$OUT/BasePhone.xcarchive" -exportPath "$OUT/export" -exportOptionsPlist "$OUT/ExportOptions.plist" \ -authenticationKeyPath "$KEYS/AuthKey_94GGSRG3FH.p8" -authenticationKeyID 94GGSRG3FH \ -authenticationKeyIssuerID 69a6de8e-080a-47e3-e053-5b8c7c11a4d1 [ "$UPLOAD" = 1 ] && rm -rf "$OUT/derived" || echo "nothing was archived, signed or uploaded: this was the plan"