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 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_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_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_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_TOKEN }}
163 run: eas env:pull production --non-interactive
164β
165 - name: Apply manual version override
166 if: steps.version_app_token.outcome == 'success'
167 env:
168 GH_TOKEN: ${{ steps.version_app_token.outputs.token }}
169 APP_SLUG: ${{ steps.version_app_token.outputs.app-slug }}
170 RELEASE_VERSION: ${{ inputs.version }}
171 run: |
172 if [ "$GITHUB_REF_TYPE" != "branch" ]; then
173 echo "Version overrides require dispatching this workflow from a branch; received $GITHUB_REF_TYPE '$GITHUB_REF_NAME'." >&2
174 exit 1
175 fi
176 if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}$ ]]; then
177 echo "Version override must contain two or three dot-separated integers; received '$RELEASE_VERSION'." >&2
178 exit 1
179 fi
180β
181 node --input-type=module -e '
182 import fs from "node:fs";
183 const path = "apps/mobile/app.config.ts";
184 const source = fs.readFileSync(path, "utf8");
185 const next = source.replace(
186 /^( version: repoEnv\.T3CODE_MOBILE_VERSION \?\? ")[^"]+(".*)$/m,
187 `$1${process.env.RELEASE_VERSION}$2`,
188 );
189 if (next === source && !source.includes(` version: repoEnv.T3CODE_MOBILE_VERSION ?? "${process.env.RELEASE_VERSION}"`)) {
190 throw new Error("Could not update app version");
191 }
192 fs.writeFileSync(path, next);
193 '
194 vp fmt apps/mobile/app.config.ts
195β
196 if git diff --quiet -- apps/mobile/app.config.ts; then
197 echo "app.config.ts is already at $RELEASE_VERSION; no version commit needed."
198 exit 0
199 fi
200β
201 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
202 git config user.name "${APP_SLUG}[bot]"
203 git config user.email "${user_id}+${APP_SLUG}[bot]@users.noreply.github.com"
204 git add apps/mobile/app.config.ts
205 git commit \
206 -m "chore(mobile): bump app version to $RELEASE_VERSION" \
207 -m "Co-authored-by: codex <codex@users.noreply.github.com>"
208 git push origin "HEAD:refs/heads/${GITHUB_REF_NAME}"
209β
210 - name: Summarize manual build version
211 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
212 working-directory: apps/mobile
213 env:
214 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
215 run: |
216 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
217 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
218 export T3CODE_MOBILE_VERSION
219 fi
220 version="$(npx expo config --json --type public | jq -r '.version')"
221 {
222 echo "## Manual $MOBILE_BUILD_PROFILE build"
223 echo
224 echo "- App version: \`$version\`"
225 echo "- Platform: \`${{ inputs.platform }}\`"
226 echo
227 echo "> Apple closes an iOS release train after App Store approval. Before building iOS, confirm \`$version\` is newer than the approved App Store version."
228 } >> "$GITHUB_STEP_SUMMARY"
229β
230 - name: Build and submit (manual)
231 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'build'
232 working-directory: apps/mobile
233 env:
234 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
235 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
236 run: eas build --platform ${{ inputs.platform }} --profile "$MOBILE_BUILD_PROFILE" --auto-submit --non-interactive --no-wait
237β
238 # @expo/fingerprint swallows autolinking errors and returns no Expo module
239 # sources, so native changes stop moving the hash and OTAs reach binaries
240 # that lack them. Refuse to publish any OTA from such a fingerprint.
241 - name: Verify fingerprints hash Expo native modules
242 if: steps.expo-token.outputs.present == 'true' && (github.event_name == 'push' || inputs.mode == 'update')
243 working-directory: apps/mobile
244 env:
245 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
246 PLATFORM: ${{ inputs.platform || 'all' }}
247 run: |
248 if [ "$PLATFORM" = "all" ]; then platforms="ios android"; else platforms="$PLATFORM"; fi
249 failed=0
250 for platform in $platforms; do
251 # eas-cli prints an environment-loaded notice to stdout before the
252 # JSON even with --json, so discard everything before the document.
253 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')"
254 if [ "${expo_modules:-0}" -eq 0 ]; then
255 failed=1
256 echo ":x: $platform: the native fingerprint hashes no Expo native modules β OTAs and builds skipped" >> "$GITHUB_STEP_SUMMARY"
257 fi
258 done
259 exit "$failed"
260β
261 - name: Publish OTA update (manual)
262 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'workflow_dispatch' && inputs.mode == 'update'
263 working-directory: apps/mobile
264 env:
265 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
266 MOBILE_BUILD_PROFILE: ${{ inputs.profile || 'production' }}
267 OTA_MESSAGE: ${{ inputs.message || format('Production OTA ({0})', github.sha) }}
268 run: |
269 if [ "$MOBILE_BUILD_PROFILE" = "testflight" ]; then
270 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
271 export T3CODE_MOBILE_VERSION
272 fi
273 eas update \
274 --channel production \
275 --environment production \
276 --platform ${{ inputs.platform }} \
277 --message "$OTA_MESSAGE" \
278 --non-interactive
279β
280 # Reconcile each version separately because the major is in the fingerprint.
281 # Production iOS only receives OTAs here; store binaries are manual releases.
282 # Failed prerelease builds are retried manually, not on every merge.
283 - id: reconcile
284 name: Publish OTA or cut store build
285 if: steps.expo-token.outputs.present == 'true' && github.event_name == 'push'
286 working-directory: apps/mobile
287 env:
288 EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
289 run: |
290 failed=0
291 message="$(git log -1 --pretty=%s | head -c 120) ($(git rev-parse --short=9 HEAD))"
292 for target in ios:production ios:testflight android:production; do
293 platform="${target%%:*}"
294 profile="${target#*:}"
295 unset T3CODE_MOBILE_VERSION
296 if [ "$profile" = "testflight" ]; then
297 T3CODE_MOBILE_VERSION="$(node -p 'require("./eas.json").build.testflight.env.T3CODE_MOBILE_VERSION')"
298 export T3CODE_MOBILE_VERSION
299 fi
300 version="$(npx expo config --json --type public | jq -r '.version')"
301 # eas-cli prints an environment-loaded notice to stdout before the
302 # JSON even with --json, so discard everything before the document.
303 hash="$(eas fingerprint:generate --platform "$platform" --environment production --json --non-interactive | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
304 matches="$(eas build:list --platform "$platform" --build-profile "$profile" --fingerprint-hash "$hash" --limit 20 --json --non-interactive)"
305 finished="$(jq '[.[] | select(.status == "FINISHED")] | length' <<<"$matches")"
306 active="$(jq '[.[] | select(.status == "NEW" or .status == "IN_QUEUE" or .status == "IN_PROGRESS")] | length' <<<"$matches")"
307 errored="$(jq '[.[] | select(.status == "ERRORED")] | length' <<<"$matches")"
308 latest_version="$(eas build:list --platform "$platform" --build-profile "$profile" --limit 1 --json --non-interactive | jq -r '.[0].appVersion // "none"')"
309β
310 if [ "$finished" -gt 0 ]; then
311 if eas update \
312 --channel production \
313 --environment production \
314 --platform "$platform" \
315 --message "$message" \
316 --non-interactive; then
317 echo ":white_check_mark: $platform/$profile: OTA published to production (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
318 else
319 failed=1
320 echo ":x: $platform/$profile: OTA publish failed (fingerprint \`$hash\`)" >> "$GITHUB_STEP_SUMMARY"
321 fi
322 fi
323β
324 # Never rebuild the released iOS version automatically.
325 if [ "$target" = "ios:production" ]; then
326 continue
327 fi
328β
329 reason=""
330 if [ "$finished" -eq 0 ] && [ "$active" -eq 0 ]; then
331 if [ "$errored" -gt 0 ]; then
332 echo ":x: $platform/$profile: the build for fingerprint \`$hash\` errored β retry with workflow_dispatch mode=build profile=$profile platform=$platform" >> "$GITHUB_STEP_SUMMARY"
333 failed=1
334 continue
335 fi
336 reason="native fingerprint \`$hash\` has no build"
337 elif [ "$latest_version" != "$version" ] && [ "$active" -eq 0 ]; then
338 reason="latest $profile build is $latest_version, expected $version"
339 fi
340β
341 if [ -z "$reason" ]; then
342 if [ "$finished" -eq 0 ]; then
343 echo ":hourglass: $platform/$profile: build for fingerprint \`$hash\` is in progress β OTA resumes on the next merge after it finishes" >> "$GITHUB_STEP_SUMMARY"
344 fi
345 continue
346 fi
347β
348 echo "$platform: $reason β building"
349 if eas build --platform "$platform" --profile "$profile" --auto-submit --non-interactive --no-wait; then
350 echo ":building_construction: $platform: scheduled production build and submission for $version ($reason)" >> "$GITHUB_STEP_SUMMARY"
351 else
352 failed=1
353 echo ":x: $platform: production build or submission failed for $version" >> "$GITHUB_STEP_SUMMARY"
354 fi
355 done
356 exit "$failed"