oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/sh
2# Base for the iPhone, to TestFlight: an archive of this checkout's commit,
3# signed for the App Store with Base's profile, exported and uploaded with
4# the App Store Connect key. A copy of agent-tools/equipo-tf/testflight.sh
5# with Base's paths, bundle ID and profile, and no widget extension.
6#
7# native/scripts/testflight.sh VERSION BUILD # the plan
8# native/scripts/testflight.sh VERSION BUILD --upload # do it
9#
10# The plan (the default) checks what it can without signing (a clean tree
11# at a pushed commit, the pinned Timeless Sans, xcodegen) and prints every
12# command. --upload runs them in a detached worktree of the commit: the
13# Apple Distribution identity, Base's App Store profile (PROFILE, by name)
14# and the App Store Connect record "Oficina Base" (Paul's portal steps)
15# must exist. The worktree is a fresh one under $TMPDIR, and only a
16# worktree this run made is removed when it's done (worktree-lib.sh).
17set -eu
18VERSION=${1:?usage: testflight.sh VERSION BUILD [--upload]}
19BUILD=${2:?usage: testflight.sh VERSION BUILD [--upload]}
20UPLOAD=0
21case "${3:-}" in --upload) UPLOAD=1 ;; "") ;; *) echo "usage: testflight.sh VERSION BUILD [--upload]" >&2; exit 2 ;; esac
22NATIVE=$(cd "$(dirname "$0")/.." && pwd)
23REPO=$(dirname "$NATIVE")
24COMMIT=$(git -C "$REPO" rev-parse HEAD)
25TEAM=9U4A84C4WK
26PROFILE=${PROFILE:-Oficina Base iOS App Store 2026-11-23}
27KEYS=$HOME/private_keys/oficina
28
29run() { echo " + $*"; [ "$UPLOAD" = 0 ] || "$@"; }
30die() { echo "error: $*" >&2; exit 1; }
31
32[ "$UPLOAD" = 1 ] && echo "uploading Base $VERSION ($BUILD) from $COMMIT" || echo "the plan for Base $VERSION ($BUILD) from $COMMIT; --upload runs it"
33case "$BUILD" in ''|*[!0-9]*) die "BUILD is not a positive integer" ;; esac
34if [ -n "$(git -C "$REPO" status --porcelain)" ]; then
35 [ "$UPLOAD" = 1 ] && die "$REPO has local changes" || echo " WARNING: local changes (--upload refuses them)"
36fi
37git -C "$REPO" branch -r --contains "$COMMIT" | grep -q . || {
38 [ "$UPLOAD" = 1 ] && die "$COMMIT is on no remote branch" || echo " WARNING: $COMMIT is on no remote branch (--upload refuses it)"; }
39"$REPO/hack/fonts.sh" check
40command -v xcodegen >/dev/null || die "no xcodegen"
41if [ "$UPLOAD" = 1 ]; then
42 CERT=$(shasum -a 1 < "$KEYS/distribution.cer" | cut -d' ' -f1 | tr a-f A-F)
43 [ -f "$KEYS/AuthKey_94GGSRG3FH.p8" ] || die "no App Store Connect key"
44else
45 CERT='<Apple Distribution certificate, from ~/private_keys/oficina/distribution.cer>'
46 echo " checked only with --upload: the distribution identity, the App Store Connect key, profile '$PROFILE'"
47fi
48
49. "$NATIVE/scripts/worktree-lib.sh"
50trap 'own_worktree_cleanup "$REPO"' EXIT
51if [ "$UPLOAD" = 1 ]; then
52 own_worktree_add "$REPO" "$COMMIT" "base-tf-$BUILD" || die "could not make a worktree of $COMMIT"
53 WT=$OWN_WT
54 echo " + git worktree add --detach $WT $COMMIT"
55else
56 WT='$TMPDIR/base-tf-'$BUILD'.XXXXXX'
57 echo " + git worktree add --detach $WT $COMMIT (a fresh directory; only it is removed after)"
58fi
59# The font is fetched, never committed: the worktree gets its own copy.
60run mkdir -p "$WT/internal/look/static/fonts/timeless/1.094"
61run cp "$REPO/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2" "$WT/internal/look/static/fonts/timeless/1.094/"
62run "$WT/native/scripts/fonts-into-bundle.sh" --release
63# The build's own scratch, fresh: never a directory someone else left.
64if [ "$UPLOAD" = 1 ]; then OUT=$(mktemp -d "${TMPDIR:-/tmp}/base-tf-build-$BUILD.XXXXXX"); else OUT='$TMPDIR/base-tf-build-'$BUILD'.XXXXXX'; fi
65run xcodegen generate --quiet --spec "$WT/native/ios/project.yml"
66run xcodebuild archive -project "$WT/native/ios/BasePhone.xcodeproj" -scheme BasePhone -destination generic/platform=iOS \
67 -derivedDataPath "$OUT/derived" -archivePath "$OUT/BasePhone.xcarchive" \
68 DEVELOPMENT_TEAM=$TEAM MARKETING_VERSION="$VERSION" CURRENT_PROJECT_VERSION="$BUILD" CODE_SIGN_STYLE=Manual \
69 CODE_SIGN_IDENTITY="$CERT" "OFICINA_PROVISIONING_PROFILE=$PROFILE"
70if [ "$UPLOAD" = 1 ]; then
71 APP=$(ls -d "$OUT/BasePhone.xcarchive/Products/Applications/"*.app)
72 codesign --verify --deep --strict "$APP"
73 /usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" -c "Print :CFBundleVersion" -c "Print :ITSAppUsesNonExemptEncryption" "$APP/Info.plist"
74 ls "$APP"/BaseNative_BaseKit.bundle/Fonts/TimelessSansVF.woff2 >/dev/null || die "Timeless Sans is not in the app"
75 cat > "$OUT/ExportOptions.plist" <<PL
76<?xml version="1.0" encoding="UTF-8"?>
77<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
78<plist version="1.0"><dict>
79<key>method</key><string>app-store-connect</string><key>teamID</key><string>$TEAM</string>
80<key>signingStyle</key><string>manual</string><key>signingCertificate</key><string>$CERT</string>
81<key>provisioningProfiles</key><dict><key>works.oficina.base</key><string>$PROFILE</string></dict>
82<key>destination</key><string>upload</string><key>manageAppVersionAndBuildNumber</key><false/>
83</dict></plist>
84PL
85else
86 echo " (checks the archive's signature, bundle ID, build, export compliance and Timeless Sans; writes ExportOptions.plist for works.oficina.base)"
87fi
88run xcodebuild -exportArchive -archivePath "$OUT/BasePhone.xcarchive" -exportPath "$OUT/export" -exportOptionsPlist "$OUT/ExportOptions.plist" \
89 -authenticationKeyPath "$KEYS/AuthKey_94GGSRG3FH.p8" -authenticationKeyID 94GGSRG3FH \
90 -authenticationKeyIssuerID 69a6de8e-080a-47e3-e053-5b8c7c11a4d1
91[ "$UPLOAD" = 1 ] && rm -rf "$OUT/derived" || echo "nothing was archived, signed or uploaded: this was the plan"
92