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 to main that touches the mobile app reconciles, per platform:
10# 1. Store builds: if the latest production build's version differs from
11# app.config.ts, cut a new build and submit it (TestFlight + Play internal
12# track). Bumping `version` is therefore all it takes to
13# start the next release train — the first build of a version enters
14# external-TestFlight beta review immediately, and later builds of the
15# same version auto-approve until that version is released. After App
16# Store approval, Apple closes the release train and `version` must be
17# bumped before another iOS build can be submitted. Releasing to the App
18# Store stays a manual App Store Connect step.
19# 2. OTA: publish a production-channel update for each platform where at
20# least one finished production build matches the current native
21# fingerprint. Old-version binaries with a matching fingerprint receive
22# it too. When native drift means no binary could install the update,
23# it is skipped and flagged in the job summary instead of published
24# into the void.
25# workflow_dispatch remains as a manual override for both modes (e.g. to
26# retry an errored build or force an OTA).
27on:
28 workflow_dispatch:
29 inputs:
30 mode:
31 description: "build (+ auto-submit to TestFlight) or update (OTA)"
32 required: true
33 type: choice
34 default: build
35 options:
36 - build
37 - update
38 platform:
39 description: "Target platform"
40 required: true
41 type: choice
42 default: ios
43 options:
44 - ios
45 - android
46 - all
47 version:
48 description: "Optional build version override (blank uses app.config.ts; an override is committed before building)"
49 required: false
50 type: string
51 message:
52 description: "OTA update message (mode=update only)"
53 required: false
54 type: string
55 push:
56 branches: [main]
57 paths:
58 - apps/mobile/**
59 - packages/client-runtime/**
60 - packages/contracts/**
61 - packages/shared/**
62 - assets/**
63 - scripts/**
64 - patches/**
65 - pnpm-lock.yaml
66 - pnpm-workspace.yaml
67 - .github/workflows/mobile-eas-production.yml
68
69# Serialize runs so OTAs publish in merge order. GitHub keeps at most one
70# queued run per group, so a burst of merges collapses into one run of the
71# newest commit — intermediate commits don't need their own OTA.
72concurrency:
73 group: mobile-eas-production
74 cancel-in-progress: false
75
76jobs:
77 production:
78 name: EAS Production ${{ github.event_name == 'push' && 'auto' || inputs.mode }}
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 - id: expo-token
87 name: Check for EXPO_TOKEN
88 env:
89 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
90 run: |
91 if [ -n "$EXPO_TOKEN" ]; then
92 echo "present=true" >> "$GITHUB_OUTPUT"
93 else
94 echo "present=false" >> "$GITHUB_OUTPUT"
95 echo "EXPO_TOKEN is not available; skipping EAS production job."
96 fi
97
98 - id: version_app_token
99 name: Mint release app token for version override
100 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build' && inputs.version != ''
101 uses: actions/create-github-app-token@v2
102 with:
103 app-id: ${{ secrets.RELEASE_APP_ID }}
104 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
105 owner: ${{ github.repository_owner }}
106
107 - name: Checkout
108 if: steps.expo-token.outputs.present == 'true'
109 uses: actions/checkout@v6
110 with:
111 fetch-depth: 0
112 token: ${{ steps.version_app_token.outputs.token || github.token }}
113 # No sparse-checkout here: it makes actions/checkout fetch with
114 # --filter=blob:none, and eas-cli archives the project via
115 # `git clone --depth 1 file://<workspace>`, which fails (exit 128)
116 # when the partial clone can't serve the unfetched blobs.
117
118 - name: Setup Vite+
119 if: steps.expo-token.outputs.present == 'true'
120 uses: voidzero-dev/setup-vp@v1
121 with:
122 node-version-file: package.json
123 cache: true
124 run-install: |
125 args:
126 - --filter=@t3tools/mobile...
127
128 - name: Expose pnpm
129 if: steps.expo-token.outputs.present == 'true'
130 run: |
131 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
132 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
133 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
134 "$vp_pnpm_bin/pnpm" --version
135
136 - name: Setup EAS
137 if: steps.expo-token.outputs.present == 'true'
138 uses: expo/expo-github-action@v8
139 with:
140 eas-version: latest
141 token: ${{ secrets.EXPO_TOKEN }}
142 # npm, not pnpm: this only installs eas-cli into the action's own
143 # tool dir, and pnpm 11 hard-fails that install on dtrace-provider's
144 # ignored build script (no allowBuilds config outside the repo).
145 packager: npm
146
147 - name: Pull production environment variables
148 if: steps.expo-token.outputs.present == 'true'
149 working-directory: apps/mobile
150 env:
151 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
152 run: eas env:pull production --non-interactive
153
154 - name: Apply manual version override
155 if: steps.version_app_token.outcome == 'success'
156 env:
157 GH_TOKEN: ${{ steps.version_app_token.outputs.token }}
158 APP_SLUG: ${{ steps.version_app_token.outputs.app-slug }}
159 RELEASE_VERSION: ${{ inputs.version }}
160 run: |
161 if [ "$GITHUB_REF_TYPE" != "branch" ]; then
162 echo "Version overrides require dispatching this workflow from a branch; received $GITHUB_REF_TYPE '$GITHUB_REF_NAME'." >&2
163 exit 1
164 fi
165 if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]]; then
166 echo "Version override must contain two or three dot-separated integers; received '$RELEASE_VERSION'." >&2
167 exit 1
168 fi
169
170 node --input-type=module -e '
171 import fs from "node:fs";
172 const path = "apps/mobile/app.config.ts";
173 const source = fs.readFileSync(path, "utf8");
174 const next = source.replace(
175 /^( version: ")[^"]+(".*)$/m,
176 `$1${process.env.RELEASE_VERSION}$2`,
177 );
178 if (next === source && !source.includes(` version: "${process.env.RELEASE_VERSION}"`)) {
179 throw new Error("Could not update app version");
180 }
181 fs.writeFileSync(path, next);
182 '
183 vp fmt apps/mobile/app.config.ts
184
185 if git diff --quiet -- apps/mobile/app.config.ts; then
186 echo "app.config.ts is already at $RELEASE_VERSION; no version commit needed."
187 exit 0
188 fi
189
190 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
191 git config user.name "${APP_SLUG}[bot]"
192 git config user.email "${user_id}+${APP_SLUG}[bot]@users.noreply.github.com"
193 git add apps/mobile/app.config.ts
194 git commit \
195 -m "chore(mobile): bump app version to $RELEASE_VERSION" \
196 -m "Co-authored-by: codex <codex@users.noreply.github.com>"
197 git push origin "HEAD:refs/heads/${GITHUB_REF_NAME}"
198
199 - name: Summarize manual build version
200 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
201 working-directory: apps/mobile
202 run: |
203 version="$(npx expo config --json --type public | jq -r '.version')"
204 {
205 echo "## Manual production build"
206 echo
207 echo "- App version: \`$version\`"
208 echo "- Platform: \`${{ inputs.platform }}\`"
209 echo
210 echo "> Apple closes an iOS release train after App Store approval. Before building iOS, confirm \`$version\` is newer than the approved App Store version."
211 } >> "$GITHUB_STEP_SUMMARY"
212
213 - name: Build and submit (manual)
214 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
215 working-directory: apps/mobile
216 env:
217 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
218 run: eas build --platform ${{ inputs.platform }} --profile production --auto-submit --non-interactive --no-wait
219
220 - name: Publish OTA update (manual)
221 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'update'
222 working-directory: apps/mobile
223 env:
224 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
225 run: |
226 eas update \
227 --channel production \
228 --environment production \
229 --platform ${{ inputs.platform }} \
230 --message "${{ inputs.message || format('Production OTA ({0})', github.sha) }}" \
231 --non-interactive
232
233 # No --status filter on build:list: an in-queue/in-progress build must
234 # count as existing, or every merge during the build window would cut a
235 # duplicate. After an errored build, retry via workflow_dispatch
236 # mode=build — pushes won't re-trigger it until the app version changes.
237 - id: store_builds
238 name: Ensure store builds exist for the current app version
239 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'push'
240 continue-on-error: true
241 working-directory: apps/mobile
242 env:
243 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
244 run: |
245 failed=0
246 version="$(npx expo config --json --type public | jq -r '.version')"
247 for platform in ios android; do
248 latest="$(eas build:list --platform "$platform" --build-profile production --limit 1 --json --non-interactive | jq -r '.[0].appVersion // "none"')"
249 if [ "$latest" = "$version" ]; then
250 echo "$platform: production build for $version already exists (or is in progress)"
251 continue
252 fi
253 echo "$platform: latest production build is $latest, app.config.ts says $version — building"
254 if eas build --platform "$platform" --profile production --auto-submit --non-interactive --no-wait; then
255 echo ":building_construction: $platform: scheduled production build and submission for $version" >> "$GITHUB_STEP_SUMMARY"
256 else
257 failed=1
258 echo ":x: $platform: production build or submission failed for $version" >> "$GITHUB_STEP_SUMMARY"
259 fi
260 done
261 exit "$failed"
262
263 - name: Publish fingerprint-gated OTA
264 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'push'
265 working-directory: apps/mobile
266 env:
267 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
268 run: |
269 message="$(git log -1 --pretty=%s | head -c 120) ($(git rev-parse --short=9 HEAD))"
270 for platform in ios android; do
271 # eas-cli prints an environment-loaded notice to stdout before the
272 # JSON even with --json, so discard everything before the document.
273 hash="$(eas fingerprint:generate --platform "$platform" --environment production --json --non-interactive | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
274 matching="$(eas build:list --platform "$platform" --build-profile production --status finished --fingerprint-hash "$hash" --limit 1 --json --non-interactive | jq 'length')"
275 if [ "$matching" -gt 0 ]; then
276 eas update \
277 --channel production \
278 --environment production \
279 --platform "$platform" \
280 --message "$message" \
281 --non-interactive
282 echo ":white_check_mark: $platform: OTA published to production (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
283 else
284 echo ":warning: $platform: no finished production build matches fingerprint \`$hash\` — OTA skipped; JS changes reach $platform only once a matching build ships" >> "$GITHUB_STEP_SUMMARY"
285 fi
286 done
287
288 - name: Propagate store build failure
289 if: steps.store_builds.outcome == 'failure'
290 run: exit 1