Open History to see the last commit
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 runs-on: blacksmith-8vcpu-ubuntu-2404
79 permissions:
80 contents: read
81 env:
82 APP_VARIANT: production
83 NODE_OPTIONS: --max-old-space-size=8192
84 steps:
85 - name: Validate TestFlight inputs
86 if: github.event_name == 'workflow_dispatch' && inputs.profile == 'testflight'
87 env:
88 PLATFORM: ${{ inputs.platform }}
89 VERSION: ${{ inputs.version }}
90 run: |
91 if [ "$PLATFORM" != "ios" ] || [ -n "$VERSION" ]; then
92 echo "::error::TestFlight uses platform=ios and its fixed version. Use production for a committed store version."
93 exit 1
94 fi
95β
96 - id: expo-token
97 name: Check for EXPO_TOKEN
98 env:
99 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
100 run: |
101 if [ -n "$EXPO_TOKEN" ]; then
102 echo "present=true" >> "$GITHUB_OUTPUT"
103 else
104 echo "present=false" >> "$GITHUB_OUTPUT"
105 echo "EXPO_TOKEN is not available; skipping EAS production job."
106 fi
107β
108 - id: version_app_token
109 name: Mint release app token for version override
110 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build' && inputs.version != '' && inputs.profile != 'testflight'
111 uses: actions/create-github-app-token@v2
112 with:
113 app-id: ${{ secrets.RELEASE_APP_ID }}
114 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
115 owner: ${{ github.repository_owner }}
116β
117 - name: Checkout
118 if: steps.expo-token.outputs.present == 'true'
119 uses: actions/checkout@v6
120 with:
121 fetch-depth: 0
122 token: ${{ steps.version_app_token.outputs.token || github.token }}
123 # No sparse-checkout here: it makes actions/checkout fetch with
124 # --filter=blob:none, and eas-cli archives the project via
125 # `git clone --depth 1 file://<workspace>`, which fails (exit 128)
126 # when the partial clone can't serve the unfetched blobs.
127β
128 - name: Setup Vite+
129 if: steps.expo-token.outputs.present == 'true'
130 uses: voidzero-dev/setup-vp@v1
131 with:
132 node-version-file: package.json
133 cache: true
134 run-install: |
135 args:
136 - --filter=@t3tools/mobile...
137β
138 - name: Expose pnpm
139 if: steps.expo-token.outputs.present == 'true'
140 run: |
141 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
142 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
143 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
144 "$vp_pnpm_bin/pnpm" --version
145β
146 - name: Setup EAS
147 if: steps.expo-token.outputs.present == 'true'
148 uses: expo/expo-github-action@v8
149 with:
150 eas-version: latest
151 token: ${{ secrets.EXPO_TOKEN }}
152 # npm, not pnpm: this only installs eas-cli into the action's own
153 # tool dir, and pnpm 11 hard-fails that install on dtrace-provider's
154 # ignored build script (no allowBuilds config outside the repo).
155 packager: npm
156β
157 - name: Pull production environment variables
158 if: steps.expo-token.outputs.present == 'true'
159 working-directory: apps/mobile
160 env:
161 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
162 run: eas env:pull production --non-interactive
163β
164 - name: Apply manual version override
165 if: steps.version_app_token.outcome == 'success'
166 env:
167 GH_TOKEN: ${{ steps.version_app_token.outputs.token }}
168 APP_SLUG: ${{ steps.version_app_token.outputs.app-slug }}
169 RELEASE_VERSION: ${{ inputs.version }}
170 run: |
171 if [ "$GITHUB_REF_TYPE" != "branch" ]; then
172 echo "Version overrides require dispatching this workflow from a branch; received $GITHUB_REF_TYPE '$GITHUB_REF_NAME'." >&2
173 exit 1
174 fi
175 if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]]; then
176 echo "Version override must contain two or three dot-separated integers; received '$RELEASE_VERSION'." >&2
177 exit 1
178 fi
179β
180 node --input-type=module -e '
181 import fs from "node:fs";
182 const path = "apps/mobile/app.config.ts";
183 const source = fs.readFileSync(path, "utf8");
184 const next = source.replace(
185 /^( version: repoEnv\.T3CODE_MOBILE_VERSION \?\? ")[^"]+(".*)$/m,
186 `$1${process.env.RELEASE_VERSION}$2`,
187 );
188 if (next === source && !source.includes(` version: repoEnv.T3CODE_MOBILE_VERSION ?? "${process.env.RELEASE_VERSION}"`)) {
189 throw new Error("Could not update app version");
190 }
191 fs.writeFileSync(path, next);
192 '
193 vp fmt apps/mobile/app.config.ts
194β
195 if git diff --quiet -- apps/mobile/app.config.ts; then
196 echo "app.config.ts is already at $RELEASE_VERSION; no version commit needed."
197 exit 0
198 fi
199β
200 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
201 git config user.name "${APP_SLUG}[bot]"
202 git config user.email "${user_id}+${APP_SLUG}[bot]@users.noreply.github.com"
203 git add apps/mobile/app.config.ts
204 git commit \
205 -m "chore(mobile): bump app version to $RELEASE_VERSION" \
206 -m "Co-authored-by: codex <codex@users.noreply.github.com>"
207 git push origin "HEAD:refs/heads/${GITHUB_REF_NAME}"
208β
209 - name: Summarize manual build version
210 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
211 working-directory: apps/mobile
212 env:
213 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
214 run: |
215 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
216 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
217 export T3CODE_MOBILE_VERSION
218 fi
219 version="$(npx expo config --json --type public | jq -r '.version')"
220 {
221 echo "## Manual $MOBILE_BUILD_PROFILE build"
222 echo
223 echo "- App version: \`$version\`"
224 echo "- Platform: \`${{ inputs.platform }}\`"
225 echo
226 echo "> Apple closes an iOS release train after App Store approval. Before building iOS, confirm \`$version\` is newer than the approved App Store version."
227 } >> "$GITHUB_STEP_SUMMARY"
228β
229 - name: Build and submit (manual)
230 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
231 working-directory: apps/mobile
232 env:
233 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
234 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
235 run: eas build --platform ${{ inputs.platform }} --profile "$MOBILE_BUILD_PROFILE" --auto-submit --non-interactive --no-wait
236β
237 # @expo/fingerprint swallows autolinking errors and returns no Expo module
238 # sources, so native changes stop moving the hash and OTAs reach binaries
239 # that lack them. Refuse to publish any OTA from such a fingerprint.
240 - name: Verify fingerprints hash Expo native modules
241 if: steps.expo-token.outputs.present == 'true' && (github.event_name == 'push' || inputs.mode == 'update')
242 working-directory: apps/mobile
243 env:
244 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
245 PLATFORM: ${{ inputs.platform || 'all' }}
246 run: |
247 if [ "$PLATFORM" = "all" ]; then platforms="ios android"; else platforms="$PLATFORM"; fi
248 failed=0
249 for platform in $platforms; do
250 # eas-cli prints an environment-loaded notice to stdout before the
251 # JSON even with --json, so discard everything before the document.
252 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')"
253 if [ "${expo_modules:-0}" -eq 0 ]; then
254 failed=1
255 echo ":x: $platform: the native fingerprint hashes no Expo native modules β OTAs and builds skipped" >> "$GITHUB_STEP_SUMMARY"
256 fi
257 done
258 exit "$failed"
259β
260 - name: Publish OTA update (manual)
261 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'update'
262 working-directory: apps/mobile
263 env:
264 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
265 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
266 OTA_MESSAGE: ${{ inputs.message || format('Production OTA ({0})', github.sha) }}
267 run: |
268 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
269 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
270 export T3CODE_MOBILE_VERSION
271 fi
272 eas update \
273 --channel production \
274 --environment production \
275 --platform ${{ inputs.platform }} \
276 --message "$OTA_MESSAGE" \
277 --non-interactive
278β
279 # Reconcile each version separately because the major is in the fingerprint.
280 # Production iOS only receives OTAs here; store binaries are manual releases.
281 # Failed prerelease builds are retried manually, not on every merge.
282 - id: reconcile
283 name: Publish OTA or cut store build
284 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'push'
285 working-directory: apps/mobile
286 env:
287 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
288 run: |
289 failed=0
290 message="$(git log -1 --pretty=%s | head -c 120) ($(git rev-parse --short=9 HEAD))"
291 for target in ios:production ios:testflight android:production; do
292 platform="${target%%:*}"
293 profile="${target#*:}"
294 unset T3CODE_MOBILE_VERSION
295 if [ "$profile" = "testflight" ]; then
296 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
297 export T3CODE_MOBILE_VERSION
298 fi
299 version="$(npx expo config --json --type public | jq -r '.version')"
300 # eas-cli prints an environment-loaded notice to stdout before the
301 # JSON even with --json, so discard everything before the document.
302 hash="$(eas fingerprint:generate --platform "$platform" --environment production --json --non-interactive | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
303 matches="$(eas build:list --platform "$platform" --build-profile "$profile" --fingerprint-hash "$hash" --limit 20 --json --non-interactive)"
304 finished="$(jq '[.[] | select(.status == "FINISHED")] | length' <<<"$matches")"
305 active="$(jq '[.[] | select(.status == "NEW" or .status == "IN_QUEUE" or .status == "IN_PROGRESS")] | length' <<<"$matches")"
306 errored="$(jq '[.[] | select(.status == "ERRORED")] | length' <<<"$matches")"
307 latest_version="$(eas build:list --platform "$platform" --build-profile "$profile" --limit 1 --json --non-interactive | jq -r '.[0].appVersion // "none"')"
308β
309 if [ "$finished" -gt 0 ]; then
310 if eas update \
311 --channel production \
312 --environment production \
313 --platform "$platform" \
314 --message "$message" \
315 --non-interactive; then
316 echo ":white_check_mark: $platform/$profile: OTA published to production (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
317 else
318 failed=1
319 echo ":x: $platform/$profile: OTA publish failed (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
320 fi
321 fi
322β
323 # Never rebuild the released iOS version automatically.
324 if [ "$target" = "ios:production" ]; then
325 continue
326 fi
327β
328 reason=""
329 if [ "$finished" -eq 0 ] && [ "$active" -eq 0 ]; then
330 if [ "$errored" -gt 0 ]; then
331 echo ":x: $platform/$profile: the build for fingerprint \`$hash\` errored β retry with workflow_dispatch mode=build profile=$profile platform=$platform" >> "$GITHUB_STEP_SUMMARY"
332 failed=1
333 continue
334 fi
335 reason="native fingerprint \`$hash\` has no build"
336 elif [ "$latest_version" != "$version" ] && [ "$active" -eq 0 ]; then
337 reason="latest $profile build is $latest_version, expected $version"
338 fi
339β
340 if [ -z "$reason" ]; then
341 if [ "$finished" -eq 0 ]; then
342 echo ":hourglass: $platform/$profile: build for fingerprint \`$hash\` is in progress β OTA resumes on the next merge after it finishes" >> "$GITHUB_STEP_SUMMARY"
343 fi
344 continue
345 fi
346β
347 echo "$platform: $reason β building"
348 if eas build --platform "$platform" --profile "$profile" --auto-submit --non-interactive --no-wait; then
349 echo ":building_construction: $platform: scheduled production build and submission for $version ($reason)" >> "$GITHUB_STEP_SUMMARY"
350 else
351 failed=1
352 echo ":x: $platform: production build or submission failed for $version" >> "$GITHUB_STEP_SUMMARY"
353 fi
354 done
355 exit "$failed"