Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobile-eas-production.yml

388 lines17.9 KB

1name: Mobile EAS Production
2​
3# Production builds and OTA updates run from CI (Linux) β€” never from a laptop.
4# Under the fingerprint runtime-version policy the fingerprint must be computed
5# in the same OS/pnpm as the EAS build; a macOS `eas build` computes a different
6# fingerprint (platform-specific deps + pnpm version) and errors. On this Linux
7# runner, with corepack pinning pnpm 10.24 in eas.json, local == build.
8#
9# Every merge reconciles native fingerprints and publishes matching OTAs.
10# iOS prereleases use the testflight profile (3.0.0); App Store binaries use
11# production and the committed app version, built manually. Both receive OTAs
12# for their own major version. Android continues using production automatically.
13# TestFlight beta review may still be required for subsequent builds.
14# Hold native-change PRs (the "πŸ“± Native Change" label) and merge them as a
15# batch to avoid a store build per PR.
16# workflow_dispatch remains as a manual override for both modes (e.g. to
17# retry an errored build or force an OTA).
18on:
19 workflow_dispatch:
20 inputs:
21 mode:
22 description: "build (+ auto-submit to TestFlight / Google Play) or update (OTA)"
23 required: true
24 type: choice
25 default: build
26 options:
27 - build
28 - update
29 profile:
30 description: "production: store release; testflight: iOS 3.0.0 beta"
31 required: true
32 type: choice
33 default: production
34 options:
35 - production
36 - testflight
37 platform:
38 description: "Target platform"
39 required: true
40 type: choice
41 default: all
42 options:
43 - ios
44 - android
45 - all
46 version:
47 description: "Optional build version override (blank uses profile default; store overrides are committed)"
48 required: false
49 type: string
50 message:
51 description: "OTA update message (mode=update only)"
52 required: false
53 type: string
54 push:
55 branches: [main]
56 paths:
57 - apps/mobile/**
58 - packages/client-runtime/**
59 - packages/contracts/**
60 - packages/shared/**
61 - assets/**
62 - scripts/**
63 - patches/**
64 - pnpm-lock.yaml
65 - pnpm-workspace.yaml
66 - .github/workflows/mobile-eas-production.yml
67​
68# Serialize runs so OTAs publish in merge order. GitHub keeps at most one
69# queued run per group, so a burst of merges collapses into one run of the
70# newest commit β€” intermediate commits don't need their own OTA.
71concurrency:
72 group: mobile-eas-production
73 cancel-in-progress: false
74​
75jobs:
76 production:
77 name: EAS ${{ inputs.profile || 'production' }} ${{ github.event_name == 'push' && 'auto' || inputs.mode }}
78 if: github.repository == 'pingdotgg/t3code'
79 runs-on: blacksmith-8vcpu-ubuntu-2404
80 permissions:
81 contents: read
82 env:
83 APP_VARIANT: production
84 NODE_OPTIONS: --max-old-space-size=8192
85 steps:
86 - name: Validate TestFlight inputs
87 if: github.event_name == 'workflow_dispatch' && inputs.profile == 'testflight'
88 env:
89 PLATFORM: ${{ inputs.platform }}
90 VERSION: ${{ inputs.version }}
91 run: |
92 if [ "$PLATFORM" != "ios" ] || [ -n "$VERSION" ]; then
93 echo "::error::TestFlight uses platform=ios and its fixed version. Use production for a committed store version."
94 exit 1
95 fi
96​
97 - id: expo-token
98 name: Check for EXPO_TOKEN
99 env:
100 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
101 run: |
102 if [ -n "$EXPO_TOKEN" ]; then
103 echo "present=true" >> "$GITHUB_OUTPUT"
104 else
105 echo "present=false" >> "$GITHUB_OUTPUT"
106 echo "EXPO_PRODUCTION_TOKEN is not available; skipping EAS production job."
107 fi
108​
109 - id: version_app_token
110 name: Mint release app token for version override
111 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build' && inputs.version != '' && inputs.profile != 'testflight'
112 uses: actions/create-github-app-token@v2
113 with:
114 app-id: ${{ secrets.RELEASE_APP_ID }}
115 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
116 owner: ${{ github.repository_owner }}
117​
118 - name: Checkout
119 if: steps.expo-token.outputs.present == 'true'
120 uses: actions/checkout@v6
121 with:
122 fetch-depth: 0
123 token: ${{ steps.version_app_token.outputs.token || github.token }}
124 # No sparse-checkout here: it makes actions/checkout fetch with
125 # --filter=blob:none, and eas-cli archives the project via
126 # `git clone --depth 1 file://<workspace>`, which fails (exit 128)
127 # when the partial clone can't serve the unfetched blobs.
128​
129 - name: Setup Vite+
130 if: steps.expo-token.outputs.present == 'true'
131 uses: voidzero-dev/setup-vp@v1
132 with:
133 node-version-file: package.json
134 cache: true
135 run-install: |
136 args:
137 - --filter=@t3tools/mobile...
138​
139 - name: Expose pnpm
140 if: steps.expo-token.outputs.present == 'true'
141 run: |
142 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
143 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
144 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
145 "$vp_pnpm_bin/pnpm" --version
146​
147 - name: Setup EAS
148 if: steps.expo-token.outputs.present == 'true'
149 uses: expo/expo-github-action@v8
150 with:
151 eas-version: latest
152 token: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
153 # npm, not pnpm: this only installs eas-cli into the action's own
154 # tool dir, and pnpm 11 hard-fails that install on dtrace-provider's
155 # ignored build script (no allowBuilds config outside the repo).
156 packager: npm
157​
158 - name: Pull production environment variables
159 if: steps.expo-token.outputs.present == 'true'
160 working-directory: apps/mobile
161 env:
162 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
163 run: |
164 eas env:pull production --non-interactive
165 # EAS commands skip dotenv, and the Android fingerprint hashes this
166 # file. Without it every merge misses the build's hash and rebuilds.
167 node --input-type=module <<'NODE'
168 import { appendFileSync, readFileSync } from "node:fs";
169 import { parseEnv } from "node:util";
170 const env = parseEnv(readFileSync(".env.local", "utf8"));
171 const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
172 if (!googleServicesFile) {
173 throw new Error("T3CODE_ANDROID_GOOGLE_SERVICES_FILE is missing from the production environment");
174 }
175 appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
176 NODE
177​
178 - name: Apply manual version override
179 if: steps.version_app_token.outcome == 'success'
180 env:
181 GH_TOKEN: ${{ steps.version_app_token.outputs.token }}
182 APP_SLUG: ${{ steps.version_app_token.outputs.app-slug }}
183 RELEASE_VERSION: ${{ inputs.version }}
184 run: |
185 if [ "$GITHUB_REF_TYPE" != "branch" ]; then
186 echo "Version overrides require dispatching this workflow from a branch; received $GITHUB_REF_TYPE '$GITHUB_REF_NAME'." >&2
187 exit 1
188 fi
189 if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]]; then
190 echo "Version override must contain two or three dot-separated integers; received '$RELEASE_VERSION'." >&2
191 exit 1
192 fi
193​
194 node --input-type=module -e '
195 import fs from "node:fs";
196 const path = "apps/mobile/app.config.ts";
197 const source = fs.readFileSync(path, "utf8");
198 const next = source.replace(
199 /^( version: repoEnv\.T3CODE_MOBILE_VERSION \?\? ")[^"]+(".*)$/m,
200 `$1${process.env.RELEASE_VERSION}$2`,
201 );
202 if (next === source && !source.includes(` version: repoEnv.T3CODE_MOBILE_VERSION ?? "${process.env.RELEASE_VERSION}"`)) {
203 throw new Error("Could not update app version");
204 }
205 fs.writeFileSync(path, next);
206 '
207 vp fmt apps/mobile/app.config.ts
208​
209 if git diff --quiet -- apps/mobile/app.config.ts; then
210 echo "app.config.ts is already at $RELEASE_VERSION; no version commit needed."
211 exit 0
212 fi
213​
214 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
215 git config user.name "${APP_SLUG}[bot]"
216 git config user.email "${user_id}+${APP_SLUG}[bot]@users.noreply.github.com"
217 git add apps/mobile/app.config.ts
218 git commit --no-verify \
219 -m "chore(mobile): bump app version to $RELEASE_VERSION" \
220 -m "Co-authored-by: codex <codex@users.noreply.github.com>"
221 git push origin "HEAD:refs/heads/${GITHUB_REF_NAME}"
222​
223 - name: Summarize manual build version
224 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
225 working-directory: apps/mobile
226 env:
227 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
228 run: |
229 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
230 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
231 export T3CODE_MOBILE_VERSION
232 fi
233 version="$(npx expo config --json --type public | jq -r '.version')"
234 {
235 echo "## Manual $MOBILE_BUILD_PROFILE build"
236 echo
237 echo "- App version: \`$version\`"
238 echo "- Platform: \`${{ inputs.platform }}\`"
239 echo
240 echo "> Apple closes an iOS release train after App Store approval. Before building iOS, confirm \`$version\` is newer than the approved App Store version."
241 } >> "$GITHUB_STEP_SUMMARY"
242​
243 - name: Build and submit (manual)
244 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
245 working-directory: apps/mobile
246 env:
247 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
248 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
249 run: eas build --platform ${{ inputs.platform }} --profile "$MOBILE_BUILD_PROFILE" --auto-submit --non-interactive --no-wait
250​
251 # @expo/fingerprint swallows autolinking errors and returns no Expo module
252 # sources, so native changes stop moving the hash and OTAs reach binaries
253 # that lack them. Refuse to publish any OTA from such a fingerprint.
254 - name: Verify fingerprints hash Expo native modules
255 if: steps.expo-token.outputs.present == 'true' && (github.event_name == 'push' || inputs.mode == 'update')
256 working-directory: apps/mobile
257 env:
258 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
259 PLATFORM: ${{ inputs.platform || 'all' }}
260 run: |
261 if [ "$PLATFORM" = "all" ]; then platforms="ios android"; else platforms="$PLATFORM"; fi
262 failed=0
263 for platform in $platforms; do
264 # eas-cli prints an environment-loaded notice to stdout before the
265 # JSON even with --json, so discard everything before the document.
266 expo_modules="$(eas fingerprint:generate --platform "$platform" --environment production --json --non-interactive | sed -n '/^{/,$p' | jq --arg reason "expoAutolinking${platform^}" '[.sources[] | select((.reasons // []) | index($reason))] | length')"
267 if [ "${expo_modules:-0}" -eq 0 ]; then
268 failed=1
269 echo ":x: $platform: the native fingerprint hashes no Expo native modules β€” OTAs and builds skipped" >> "$GITHUB_STEP_SUMMARY"
270 fi
271 done
272 exit "$failed"
273​
274 - name: Publish OTA update (manual)
275 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'update'
276 working-directory: apps/mobile
277 env:
278 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
279 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
280 OTA_MESSAGE: ${{ inputs.message || format('Production OTA ({0})', github.sha) }}
281 run: |
282 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
283 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
284 export T3CODE_MOBILE_VERSION
285 fi
286 eas update \
287 --channel production \
288 --environment production \
289 --platform ${{ inputs.platform }} \
290 --message "$OTA_MESSAGE" \
291 --emit-metadata \
292 --non-interactive
293​
294 # Reconcile each version separately because the major is in the fingerprint.
295 # Production iOS only receives OTAs here; store binaries are manual releases.
296 # Failed prerelease builds are retried manually, not on every merge.
297 - id: reconcile
298 name: Publish OTA or cut store build
299 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'push'
300 working-directory: apps/mobile
301 env:
302 EXPO_TOKEN: ${{ secrets.EXPO_PRODUCTION_TOKEN }}
303 run: |
304 failed=0
305 message="$(git log -1 --pretty=%s | head -c 120) ($(git rev-parse --short=9 HEAD))"
306 for target in ios:production ios:testflight android:production; do
307 platform="${target%%:*}"
308 profile="${target#*:}"
309 unset T3CODE_MOBILE_VERSION
310 if [ "$profile" = "testflight" ]; then
311 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
312 export T3CODE_MOBILE_VERSION
313 fi
314 version="$(npx expo config --json --type public | jq -r '.version')"
315 # eas-cli prints an environment-loaded notice to stdout before the
316 # JSON even with --json, so discard everything before the document.
317 hash="$(eas fingerprint:generate --platform "$platform" --environment production --json --non-interactive | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
318 matches="$(eas build:list --platform "$platform" --build-profile "$profile" --fingerprint-hash "$hash" --limit 20 --json --non-interactive)"
319 finished="$(jq '[.[] | select(.status == "FINISHED")] | length' <<<"$matches")"
320 active="$(jq '[.[] | select(.status == "NEW" or .status == "IN_QUEUE" or .status == "IN_PROGRESS")] | length' <<<"$matches")"
321 errored="$(jq '[.[] | select(.status == "ERRORED")] | length' <<<"$matches")"
322 latest_version="$(eas build:list --platform "$platform" --build-profile "$profile" --limit 1 --json --non-interactive | jq -r '.[0].appVersion // "none"')"
323​
324 if [ "$finished" -gt 0 ]; then
325 if eas update \
326 --channel production \
327 --environment production \
328 --platform "$platform" \
329 --message "$message" \
330 --emit-metadata \
331 --non-interactive; then
332 echo ":white_check_mark: $platform/$profile: OTA published to production (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
333 # The next target's export replaces dist; keep this one for the map upload.
334 rm -rf "dist-$platform-$profile" && mv dist "dist-$platform-$profile"
335 else
336 failed=1
337 echo ":x: $platform/$profile: OTA publish failed (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
338 fi
339 fi
340​
341 # Never rebuild the released iOS version automatically.
342 if [ "$target" = "ios:production" ]; then
343 continue
344 fi
345​
346 reason=""
347 if [ "$finished" -eq 0 ] && [ "$active" -eq 0 ]; then
348 if [ "$errored" -gt 0 ]; then
349 echo ":x: $platform/$profile: the build for fingerprint \`$hash\` errored β€” retry with workflow_dispatch mode=build profile=$profile platform=$platform" >> "$GITHUB_STEP_SUMMARY"
350 failed=1
351 continue
352 fi
353 reason="native fingerprint \`$hash\` has no build"
354 elif [ "$latest_version" != "$version" ] && [ "$active" -eq 0 ]; then
355 reason="latest $profile build is $latest_version, expected $version"
356 fi
357​
358 if [ -z "$reason" ]; then
359 if [ "$finished" -eq 0 ]; then
360 echo ":hourglass: $platform/$profile: build for fingerprint \`$hash\` is in progress β€” OTA resumes on the next merge after it finishes" >> "$GITHUB_STEP_SUMMARY"
361 fi
362 continue
363 fi
364​
365 echo "$platform: $reason β€” building"
366 if eas build --platform "$platform" --profile "$profile" --auto-submit --non-interactive --no-wait; then
367 echo ":building_construction: $platform: scheduled production build and submission for $version ($reason)" >> "$GITHUB_STEP_SUMMARY"
368 else
369 failed=1
370 echo ":x: $platform: production build or submission failed for $version" >> "$GITHUB_STEP_SUMMARY"
371 fi
372 done
373 exit "$failed"
374​
375 # Lets the relay symbolicate crash stacks from the updates published
376 # above. A step of its own so the R2 credentials reach only this script,
377 # not `eas update` and the dependencies it runs. Never fails the job.
378 - name: Upload OTA source maps
379 if: ${{ !cancelled() && steps.expo-token.outputs.present == 'true' }}
380 working-directory: apps/mobile
381 env:
382 MOBILE_SOURCEMAPS_R2: ${{ secrets.MOBILE_SOURCEMAPS_R2 }}
383 run: |
384 for dir in dist dist-*; do
385 if [ -f "$dir/eas-update-metadata.json" ]; then
386 node scripts/upload-sourcemaps.mts ota "$dir"
387 fi
388 done