@devries-cameron20 / t3code-1 / commits / b78c04d3e1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

ci(mobile): Android PR preview clients build on Blacksmith (#33618)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

Julius Marminge committed Nov 9, 2026 at 18:05 UTC b78c04d3e1588f6579bd72a709d8168f3e8ab58f
5 files changed +747 -7
.github/scripts/mobile-preview-comment.cjs new
+126
@@ -0,0 +1,126 @@
1 +// The Android half of the mobile preview comment. The android job writes the fingerprint and
2 +// the update; the android-build job adds the client's install link a few minutes later. Each
3 +// run merges what it knows into the state kept in the comment's first line.
4 +const MARKER = "mobile-preview-android";
5 +const PROJECT_ID = "d763fcb8-d37c-41ea-a773-b54a0ab4a454";
6 +const APP_SCHEME = "t3-code";
7 +
8 +function readState(body) {
9 + const match = new RegExp(`^<!-- ${MARKER} (\\{.*\\}) -->`).exec(body ?? "");
10 + if (!match) return null;
11 + try {
12 + const state = JSON.parse(match[1]);
13 + const text = (value) => (typeof value === "string" ? value : "");
14 + return {
15 + fingerprint: text(state.fingerprint),
16 + client: text(state.client),
17 + group: text(state.group),
18 + };
19 + } catch {
20 + return null;
21 + }
22 +}
23 +
24 +/**
25 + * New values win; a new fingerprint drops the old fingerprint's client. A build that finishes
26 + * after the PR moved to another fingerprint changes nothing: its client cannot run the update
27 + * the comment now shows.
28 + */
29 +function mergeState(previous, next) {
30 + const buildOnly = Boolean(next.client) && !next.group;
31 + if (
32 + buildOnly &&
33 + previous?.fingerprint &&
34 + next.fingerprint &&
35 + previous.fingerprint !== next.fingerprint
36 + ) {
37 + return previous;
38 + }
39 + const fingerprint = next.fingerprint || previous?.fingerprint || "";
40 + const sameFingerprint = !previous?.fingerprint || previous.fingerprint === fingerprint;
41 + return {
42 + fingerprint,
43 + client: next.client || (sameFingerprint ? (previous?.client ?? "") : ""),
44 + group: next.group || previous?.group || "",
45 + };
46 +}
47 +
48 +function render(state, runUrl) {
49 + const qr = `https://qr.expo.dev/eas-update?appScheme=${APP_SCHEME}&projectId=${PROJECT_ID}&groupId=${state.group}`;
50 + const rows = [
51 + `<!-- ${MARKER} ${JSON.stringify(state)} -->`,
52 + "🤖 Android preview",
53 + "",
54 + "&nbsp; | 🤖 Android",
55 + "--- | ---",
56 + `Fingerprint | ${state.fingerprint || "n/a"}`,
57 + `Dev client | ${state.client ? `[Install](${state.client})` : `Building on Blacksmith ([run](${runUrl})); this comment gets the install link when it finishes`}`,
58 + ];
59 + if (state.group) {
60 + rows.push(
61 + `Update Details | [Update Permalink](https://expo.dev/projects/${PROJECT_ID}/updates/${state.group})`,
62 + `Update QR | <a href="${qr}"><img src="${qr}" width="250px" height="250px" /></a>`,
63 + );
64 + }
65 + return rows.join("\n");
66 +}
67 +
68 +async function github(path, init = {}) {
69 + const response = await fetch(`https://api.github.com${path}`, {
70 + ...init,
71 + headers: {
72 + authorization: `Bearer ${process.env.GH_TOKEN}`,
73 + accept: "application/vnd.github+json",
74 + "content-type": "application/json",
75 + ...init.headers,
76 + },
77 + });
78 + if (!response.ok) {
79 + throw new Error(
80 + `GitHub ${init.method ?? "GET"} ${path}: ${response.status} ${await response.text()}`,
81 + );
82 + }
83 + return response.json();
84 +}
85 +
86 +async function main() {
87 + const repository = process.env.GITHUB_REPOSITORY;
88 + const pr = process.env.PR;
89 + if (!repository || !pr || !process.env.GH_TOKEN) {
90 + throw new Error("GITHUB_REPOSITORY, PR and GH_TOKEN are required.");
91 + }
92 + const runUrl = `${process.env.GITHUB_SERVER_URL}/${repository}/actions/runs/${process.env.GITHUB_RUN_ID}`;
93 + let existing = null;
94 + for (let page = 1; existing === null; page++) {
95 + const comments = await github(
96 + `/repos/${repository}/issues/${pr}/comments?per_page=100&page=${page}`,
97 + );
98 + // Only this workflow's own comment: anyone can post the marker, and nobody else's is editable.
99 + existing =
100 + comments.find(
101 + (comment) =>
102 + comment.user?.login === "github-actions[bot]" && readState(comment.body) !== null,
103 + ) ?? null;
104 + if (comments.length < 100) break;
105 + }
106 + const state = mergeState(readState(existing?.body), {
107 + fingerprint: process.env.FINGERPRINT ?? "",
108 + client: process.env.CLIENT ?? "",
109 + group: process.env.GROUP ?? "",
110 + });
111 + const body = JSON.stringify({ body: render(state, runUrl) });
112 + if (existing) {
113 + await github(`/repos/${repository}/issues/comments/${existing.id}`, { method: "PATCH", body });
114 + } else {
115 + await github(`/repos/${repository}/issues/${pr}/comments`, { method: "POST", body });
116 + }
117 +}
118 +
119 +if (require.main === module) {
120 + main().catch((error) => {
121 + console.error(error);
122 + process.exitCode = 1;
123 + });
124 +}
125 +
126 +module.exports = { mergeState, readState, render };
.github/scripts/mobile-preview-comment.test.cjs new
+62
@@ -0,0 +1,62 @@
1 +const assert = require("node:assert/strict");
2 +const test = require("node:test");
3 +
4 +const { mergeState, readState, render } = require("./mobile-preview-comment.cjs");
5 +
6 +const fingerprint = "c31608b37a8a2dca35ccee39cfd2ec7305042629";
7 +const run = "https://github.com/pingdotgg/t3code/actions/runs/1";
8 +
9 +test("the comment round-trips its state", () => {
10 + const state = { fingerprint, client: "", group: "8e413a0a" };
11 + const body = render(state, run);
12 + assert.deepEqual(readState(body), state);
13 + assert.match(
14 + body,
15 + /Building on Blacksmith \(\[run\]\(https:\/\/github\.com\/pingdotgg\/t3code\/actions\/runs\/1\)\)/,
16 + );
17 + assert.match(
18 + body,
19 + /qr\.expo\.dev\/eas-update\?appScheme=t3-code&projectId=[0-9a-f-]+&groupId=8e413a0a/,
20 + );
21 + assert.equal(readState("🚀 Expo continuous deployment is ready!"), null);
22 +});
23 +
24 +test("the build job adds the install link without losing the update", () => {
25 + const first = mergeState(null, { fingerprint, client: "", group: "8e413a0a" });
26 + const built = mergeState(first, { fingerprint, client: "https://expo.dev/a/b", group: "" });
27 + assert.deepEqual(built, { fingerprint, client: "https://expo.dev/a/b", group: "8e413a0a" });
28 + assert.match(render(built, run), /Dev client \| \[Install\]\(https:\/\/expo\.dev\/a\/b\)/);
29 +});
30 +
31 +test("a new fingerprint drops the old client; the same one keeps it", () => {
32 + const built = { fingerprint, client: "https://expo.dev/a/b", group: "old" };
33 + assert.deepEqual(mergeState(built, { fingerprint, client: "", group: "new" }), {
34 + fingerprint,
35 + client: "https://expo.dev/a/b",
36 + group: "new",
37 + });
38 + assert.deepEqual(mergeState(built, { fingerprint: "f".repeat(40), client: "", group: "new" }), {
39 + fingerprint: "f".repeat(40),
40 + client: "",
41 + group: "new",
42 + });
43 +});
44 +
45 +test("a build that finishes after the PR moved to another fingerprint changes nothing", () => {
46 + const current = { fingerprint: "f".repeat(40), client: "", group: "new" };
47 + assert.deepEqual(
48 + mergeState(current, { fingerprint, client: "https://expo.dev/a/b", group: "" }),
49 + current,
50 + );
51 +});
52 +
53 +test("state from the comment is always three strings", () => {
54 + assert.deepEqual(
55 + readState('<!-- mobile-preview-android {"fingerprint":5,"client":null} -->\nx'),
56 + {
57 + fingerprint: "",
58 + client: "",
59 + group: "",
60 + },
61 + );
62 +});
.github/workflows/ci.yml
+1 -1
@@ -314,7 +314,7 @@ jobs:
314 run: python3 -B .github/scripts/stage-preview-bundle.test.py
315
316 - name: Test release checks
317 - run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs
317 + run: node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs .github/scripts/mobile-preview-comment.test.cjs
318
319 - name: Finish installing browser secret helper build libraries
320 timeout-minutes: 5
.github/workflows/mobile-eas-preview-fork.yml
+214 -4
@@ -1,8 +1,8 @@
1 name: Mobile EAS Preview (Fork)
2
3 # EAS previews for fork PRs. This runs the PR's code with an Expo token: the
4 -# app config and plugins run on this runner, and native builds run on EAS
5 -# with preview signing credentials. The label is the maintainer's sign-off
4 +# app config and plugins run on this runner, the iOS client builds on EAS and
5 +# the Android one on Blacksmith (android-build), with preview signing credentials. The label is the maintainer's sign-off
6 # that they reviewed that code, so it covers exactly the commit it was applied
7 # to: this pins that commit and consumes the label before running anything. A
8 # later push deploys nothing until the label is applied again.
@@ -29,6 +29,9 @@ jobs:
29 permissions:
30 contents: read
31 pull-requests: write
32 + outputs:
33 + build: ${{ steps.client.outputs.build }}
34 + fingerprint: ${{ steps.client.outputs.fingerprint }}
35 env:
36 APP_VARIANT: preview
37 NODE_OPTIONS: --max-old-space-size=8192
@@ -76,9 +79,43 @@ jobs:
79 with:
80 ref: ${{ github.event.pull_request.head.sha }}
81 fetch-depth: 0
79 - persist-credentials: false
82 # No sparse-checkout: see mobile-eas-preview.yml.
83
84 + # The comment script comes from main, not from the PR.
85 + - name: Checkout trusted scripts
86 + if: steps.expo-token.outputs.present == 'true'
87 + uses: actions/checkout@v6
88 + with:
89 + path: .trusted
90 + sparse-checkout: .github/scripts
91 +
92 + # The steps below run the PR's dependency and build scripts; they get no token.
93 + # checkout keeps it in a file under RUNNER_TEMP that .git/config includes, so both
94 + # go. Asking checkout not to persist it fails here: that cleanup runs `git submodule
95 + # foreach`, which stops at the vendored gitlinks under .repos (no .gitmodules entry).
96 + - name: Drop checkout credentials
97 + if: steps.expo-token.outputs.present == 'true'
98 + run: |
99 + for dir in . .trusted; do
100 + [ -e "$dir/.git" ] || continue
101 + git -C "$dir" config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
102 + rm -f "$file"
103 + git -C "$dir" config --local --unset-all "$key"
104 + done
105 + git -C "$dir" config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
106 + git -C "$dir" config --local --unset-all "$key"
107 + done
108 + if git -C "$dir" config --local --get-regexp 'extraheader|includeif'; then
109 + echo "::error::checkout credentials are still configured in $dir"
110 + exit 1
111 + fi
112 + done
113 + rm -f "$RUNNER_TEMP"/git-credentials-*.config
114 + if ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
115 + echo "::error::a checkout credential file is still present"
116 + exit 1
117 + fi
118 +
119 # No caches: pull_request_target saves them under main's scope, where
120 # trusted workflows with other secrets would restore what PR code wrote.
121 - name: Setup Vite+
@@ -139,7 +176,180 @@ jobs:
176 with:
177 profile: preview:dev
178 branch: pr-${{ github.event.pull_request.number }}
142 - platform: all
179 + # Android is below: its client builds on Blacksmith (android-build).
180 + platform: ios
181 environment: preview
182 working-directory: apps/mobile
183 github-token: ${{ secrets.GITHUB_TOKEN }}
184 +
185 + # Android, as in mobile-eas-preview.yml: the same fingerprint command the Expo
186 + # action runs. A client built for a same-repo PR (its tag) or by EAS is reused.
187 + - id: client
188 + name: Find the Android client for this fingerprint
189 + if: steps.expo-token.outputs.present == 'true'
190 + working-directory: apps/mobile
191 + shell: bash
192 + env:
193 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
194 + run: |
195 + hash="$(eas env:exec --non-interactive preview "npx expo-updates fingerprint:generate --platform android" | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
196 + echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
197 + tag="mobile-android-preview-build/$hash"
198 + link=""
199 + if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
200 + link="$(git tag -l --format='%(contents:subject)' "$tag")"
201 + else
202 + link="$(eas build:list --platform android --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
203 + | sed -n '/^\[/,$p' \
204 + | jq -r --arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" '[.[] | select((.expirationDate // "9999") > $now)][0] | select(. != null) | "https://expo.dev/accounts/pingdotgg/projects/t3-code/builds/\(.id)"')"
205 + fi
206 + echo "link=$link" >> "$GITHUB_OUTPUT"
207 + if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
208 +
209 + - id: update
210 + name: Publish the Android update
211 + if: steps.expo-token.outputs.present == 'true'
212 + working-directory: apps/mobile
213 + shell: bash
214 + env:
215 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
216 + PR: ${{ github.event.pull_request.number }}
217 + run: |
218 + group="$(eas update --auto --branch "pr-$PR" --platform android --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
219 + echo "group=$group" >> "$GITHUB_OUTPUT"
220 +
221 + - name: Comment
222 + if: steps.expo-token.outputs.present == 'true'
223 + env:
224 + GH_TOKEN: ${{ github.token }}
225 + PR: ${{ github.event.pull_request.number }}
226 + FINGERPRINT: ${{ steps.client.outputs.fingerprint }}
227 + CLIENT: ${{ steps.client.outputs.link }}
228 + GROUP: ${{ steps.update.outputs.group }}
229 + run: node .trusted/.github/scripts/mobile-preview-comment.cjs
230 +
231 + # The reviewed commit's Android client, built cold: no sticky disk, because PR
232 + # code could leave Gradle or ccache state that trusted builds would restore, and
233 + # no build record tag, so nobody else is served an APK a fork's code built.
234 + android-build:
235 + name: Android preview client
236 + needs: preview
237 + if: needs.preview.outputs.build == 'true'
238 + runs-on: blacksmith-32vcpu-ubuntu-2404
239 + timeout-minutes: 60
240 + permissions:
241 + contents: read
242 + pull-requests: write
243 + env:
244 + APP_VARIANT: preview
245 + NODE_OPTIONS: --max-old-space-size=8192
246 + MOBILE_VERSION_POLICY: fingerprint
247 + FINGERPRINT: ${{ needs.preview.outputs.fingerprint }}
248 + # Phones only: emulators use the development client from the native-client cache.
249 + ORG_GRADLE_PROJECT_reactNativeArchitectures: armeabi-v7a,arm64-v8a
250 + steps:
251 + - name: Checkout reviewed commit
252 + uses: actions/checkout@v6
253 + with:
254 + ref: ${{ github.event.pull_request.head.sha }}
255 + fetch-depth: 0
256 +
257 + # The comment script comes from main, not from the PR.
258 + - name: Checkout trusted scripts
259 + uses: actions/checkout@v6
260 + with:
261 + path: .trusted
262 + sparse-checkout: .github/scripts
263 +
264 + # The steps below run the PR's dependency and build scripts; they get no token.
265 + # checkout keeps it in a file under RUNNER_TEMP that .git/config includes, so both
266 + # go. Asking checkout not to persist it fails here: that cleanup runs `git submodule
267 + # foreach`, which stops at the vendored gitlinks under .repos (no .gitmodules entry).
268 + - name: Drop checkout credentials
269 + run: |
270 + for dir in . .trusted; do
271 + [ -e "$dir/.git" ] || continue
272 + git -C "$dir" config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
273 + rm -f "$file"
274 + git -C "$dir" config --local --unset-all "$key"
275 + done
276 + git -C "$dir" config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
277 + git -C "$dir" config --local --unset-all "$key"
278 + done
279 + if git -C "$dir" config --local --get-regexp 'extraheader|includeif'; then
280 + echo "::error::checkout credentials are still configured in $dir"
281 + exit 1
282 + fi
283 + done
284 + rm -f "$RUNNER_TEMP"/git-credentials-*.config
285 + if ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
286 + echo "::error::a checkout credential file is still present"
287 + exit 1
288 + fi
289 +
290 + - name: Setup Node
291 + uses: actions/setup-node@v6
292 + with:
293 + node-version-file: package.json
294 +
295 + - name: Enable corepack
296 + run: |
297 + npm install --global corepack@latest
298 + corepack enable
299 + pnpm --version
300 +
301 + - name: Install mobile dependencies
302 + run: pnpm install --frozen-lockfile --filter=@t3tools/mobile...
303 +
304 + - name: Setup Java
305 + uses: actions/setup-java@v5
306 + with:
307 + distribution: temurin
308 + java-version: 17
309 +
310 + - name: Setup EAS
311 + uses: expo/expo-github-action@v8
312 + with:
313 + eas-version: latest
314 + eas-cache: false
315 + token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
316 + packager: npm
317 +
318 + - name: Pull preview environment variables
319 + working-directory: apps/mobile
320 + env:
321 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
322 + run: |
323 + eas env:pull preview --non-interactive
324 + node --input-type=module <<'NODE'
325 + import { appendFileSync, readFileSync } from "node:fs";
326 + import { parseEnv } from "node:util";
327 + const env = parseEnv(readFileSync(".env.local", "utf8"));
328 + const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
329 + if (googleServicesFile) {
330 + appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
331 + }
332 + NODE
333 +
334 + - id: build
335 + name: Build and upload
336 + working-directory: apps/mobile
337 + shell: bash
338 + env:
339 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
340 + run: |
341 + eas build --local --platform android --profile preview:dev --non-interactive --output "$RUNNER_TEMP/t3code-preview.apk"
342 + eas upload --platform android --build-path "$RUNNER_TEMP/t3code-preview.apk" --fingerprint "$FINGERPRINT" --non-interactive --json | tee "$RUNNER_TEMP/upload.json"
343 + link="$(sed -n '/^{/,$p' "$RUNNER_TEMP/upload.json" | jq -r '.url // empty')"
344 + if [ -z "$link" ]; then
345 + echo "::error::eas upload returned no install link"
346 + exit 1
347 + fi
348 + echo "link=$link" >> "$GITHUB_OUTPUT"
349 +
350 + - name: Comment
351 + env:
352 + GH_TOKEN: ${{ github.token }}
353 + PR: ${{ github.event.pull_request.number }}
354 + CLIENT: ${{ steps.build.outputs.link }}
355 + run: node .trusted/.github/scripts/mobile-preview-comment.cjs
.github/workflows/mobile-eas-preview.yml
+344 -2
@@ -6,7 +6,7 @@ on:
6
7 jobs:
8 preview:
9 - name: EAS Preview
9 + name: EAS Preview (iOS)
10 # Fork PRs deploy one reviewed commit per label through mobile-eas-preview-fork.yml.
11 if: |
12 github.event.pull_request.head.repo.full_name == github.repository &&
@@ -107,7 +107,349 @@ jobs:
107 with:
108 profile: preview:dev
109 branch: pr-${{ github.event.pull_request.number }}
110 - platform: all
110 + # Android is the android job below: its client builds on Blacksmith.
111 + platform: ios
112 environment: preview
113 working-directory: apps/mobile
114 github-token: ${{ secrets.GITHUB_TOKEN }}
115 +
116 + # Android publishes its own update and comment, because the Expo action can only
117 + # find a client that EAS built. A fingerprint with no client is built by
118 + # android-build with `eas build --local` on Blacksmith (about 4 minutes warm,
119 + # against about 40 on EAS) and recorded as a mobile-android-preview-build/<fingerprint>
120 + # tag whose message is the install link. Clients EAS built earlier still count.
121 + android:
122 + name: EAS Preview (Android)
123 + if: |
124 + github.event.pull_request.head.repo.full_name == github.repository &&
125 + contains(github.event.pull_request.labels.*.name, '🚀 Mobile Continuous Deployment') &&
126 + (github.event.action != 'labeled' || github.event.label.name == '🚀 Mobile Continuous Deployment')
127 + runs-on: blacksmith-8vcpu-ubuntu-2404
128 + concurrency:
129 + group: mobile-eas-preview-android-${{ github.event.pull_request.number }}
130 + cancel-in-progress: true
131 + permissions:
132 + contents: read
133 + pull-requests: write
134 + outputs:
135 + build: ${{ steps.client.outputs.build }}
136 + fingerprint: ${{ steps.client.outputs.fingerprint }}
137 + env:
138 + APP_VARIANT: preview
139 + NODE_OPTIONS: --max-old-space-size=8192
140 + MOBILE_VERSION_POLICY: fingerprint
141 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
142 + GH_TOKEN: ${{ github.token }}
143 + PR: ${{ github.event.pull_request.number }}
144 + steps:
145 + - id: expo-token
146 + name: Check for EXPO_PREVIEW_TOKEN
147 + run: |
148 + if [ -n "$EXPO_TOKEN" ]; then
149 + echo "present=true" >> "$GITHUB_OUTPUT"
150 + else
151 + echo "present=false" >> "$GITHUB_OUTPUT"
152 + echo "EXPO_PREVIEW_TOKEN is not available; skipping the Android preview."
153 + fi
154 +
155 + - name: Checkout
156 + if: steps.expo-token.outputs.present == 'true'
157 + uses: actions/checkout@v6
158 + with:
159 + fetch-depth: 0
160 +
161 + # The steps below run the PR's dependency and build scripts; they get no token.
162 + # checkout keeps it in a file under RUNNER_TEMP that .git/config includes, so both
163 + # go. Asking checkout not to persist it fails here: that cleanup runs `git submodule
164 + # foreach`, which stops at the vendored gitlinks under .repos (no .gitmodules entry).
165 + - name: Drop checkout credentials
166 + if: steps.expo-token.outputs.present == 'true'
167 + run: |
168 + for dir in . .trusted; do
169 + [ -e "$dir/.git" ] || continue
170 + git -C "$dir" config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
171 + rm -f "$file"
172 + git -C "$dir" config --local --unset-all "$key"
173 + done
174 + git -C "$dir" config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
175 + git -C "$dir" config --local --unset-all "$key"
176 + done
177 + if git -C "$dir" config --local --get-regexp 'extraheader|includeif'; then
178 + echo "::error::checkout credentials are still configured in $dir"
179 + exit 1
180 + fi
181 + done
182 + rm -f "$RUNNER_TEMP"/git-credentials-*.config
183 + if ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
184 + echo "::error::a checkout credential file is still present"
185 + exit 1
186 + fi
187 +
188 + - name: Setup Vite+
189 + if: steps.expo-token.outputs.present == 'true'
190 + uses: voidzero-dev/setup-vp@v1
191 + with:
192 + node-version-file: package.json
193 + cache: true
194 + run-install: |
195 + args:
196 + - --filter=@t3tools/mobile...
197 +
198 + - name: Expose pnpm
199 + if: steps.expo-token.outputs.present == 'true'
200 + run: |
201 + pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
202 + vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
203 + echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
204 + "$vp_pnpm_bin/pnpm" --version
205 +
206 + - name: Setup EAS
207 + if: steps.expo-token.outputs.present == 'true'
208 + uses: expo/expo-github-action@v8
209 + with:
210 + eas-version: latest
211 + token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
212 + packager: npm
213 +
214 + - name: Pull preview environment variables
215 + if: steps.expo-token.outputs.present == 'true'
216 + working-directory: apps/mobile
217 + run: |
218 + eas env:pull preview --non-interactive
219 + node --input-type=module <<'NODE'
220 + import { appendFileSync, readFileSync } from "node:fs";
221 + import { parseEnv } from "node:util";
222 + const env = parseEnv(readFileSync(".env.local", "utf8"));
223 + const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
224 + if (googleServicesFile) {
225 + appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
226 + }
227 + NODE
228 +
229 + # The same command the Expo action runs, so this is the runtime version the update gets.
230 + - id: client
231 + name: Find the client for this fingerprint
232 + if: steps.expo-token.outputs.present == 'true'
233 + working-directory: apps/mobile
234 + shell: bash
235 + run: |
236 + hash="$(eas env:exec --non-interactive preview "npx expo-updates fingerprint:generate --platform android" | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
237 + echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
238 + tag="mobile-android-preview-build/$hash"
239 + link=""
240 + if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
241 + link="$(git tag -l --format='%(contents:subject)' "$tag")"
242 + else
243 + # A client EAS built before this job existed; expired ones are gone.
244 + link="$(eas build:list --platform android --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
245 + | sed -n '/^\[/,$p' \
246 + | jq -r --arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" '[.[] | select((.expirationDate // "9999") > $now)][0] | select(. != null) | "https://expo.dev/accounts/pingdotgg/projects/t3-code/builds/\(.id)"')"
247 + fi
248 + echo "link=$link" >> "$GITHUB_OUTPUT"
249 + if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
250 + echo "android fingerprint \`$hash\`: ${link:-no client yet, building on Blacksmith}" >> "$GITHUB_STEP_SUMMARY"
251 +
252 + - id: update
253 + name: Publish the update
254 + if: steps.expo-token.outputs.present == 'true'
255 + working-directory: apps/mobile
256 + shell: bash
257 + run: |
258 + group="$(eas update --auto --branch "pr-$PR" --platform android --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
259 + echo "group=$group" >> "$GITHUB_OUTPUT"
260 +
261 + - name: Comment
262 + if: steps.expo-token.outputs.present == 'true'
263 + env:
264 + FINGERPRINT: ${{ steps.client.outputs.fingerprint }}
265 + CLIENT: ${{ steps.client.outputs.link }}
266 + GROUP: ${{ steps.update.outputs.group }}
267 + run: node .github/scripts/mobile-preview-comment.cjs
268 +
269 + android-build:
270 + name: Android preview client
271 + needs: android
272 + if: needs.android.outputs.build == 'true'
273 + runs-on: blacksmith-32vcpu-ubuntu-2404
274 + timeout-minutes: 60
275 + concurrency:
276 + # One build per fingerprint; a second PR with the same one finds the tag.
277 + group: mobile-android-preview-build-${{ needs.android.outputs.fingerprint }}
278 + cancel-in-progress: false
279 + permissions:
280 + contents: write # pushes the build record tag
281 + pull-requests: write
282 + env:
283 + APP_VARIANT: preview
284 + NODE_OPTIONS: --max-old-space-size=8192
285 + MOBILE_VERSION_POLICY: fingerprint
286 + EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
287 + FINGERPRINT: ${{ needs.android.outputs.fingerprint }}
288 + BUILD_TAG: mobile-android-preview-build/${{ needs.android.outputs.fingerprint }}
289 + # Phones only: emulators use the development client from the native-client cache.
290 + ORG_GRADLE_PROJECT_reactNativeArchitectures: armeabi-v7a,arm64-v8a
291 + steps:
292 + - name: Checkout
293 + uses: actions/checkout@v6
294 + with:
295 + fetch-depth: 0
296 +
297 + - id: record
298 + name: Check build record
299 + run: |
300 + if git fetch --quiet origin "refs/tags/$BUILD_TAG:refs/tags/$BUILD_TAG" 2>/dev/null; then
301 + echo "built=true" >> "$GITHUB_OUTPUT"
302 + echo "link=$(git tag -l --format='%(contents:subject)' "$BUILD_TAG")" >> "$GITHUB_OUTPUT"
303 + fi
304 +
305 + # The steps below run the PR's dependency and build scripts; they get no token.
306 + # checkout keeps it in a file under RUNNER_TEMP that .git/config includes, so both
307 + # go. Asking checkout not to persist it fails here: that cleanup runs `git submodule
308 + # foreach`, which stops at the vendored gitlinks under .repos (no .gitmodules entry).
309 + - name: Drop checkout credentials
310 + run: |
311 + for dir in . .trusted; do
312 + [ -e "$dir/.git" ] || continue
313 + git -C "$dir" config --local --get-regexp '^includeif\..*\.path$' | while read -r key file; do
314 + rm -f "$file"
315 + git -C "$dir" config --local --unset-all "$key"
316 + done
317 + git -C "$dir" config --local --name-only --get-regexp '^http\..*\.extraheader$' | while read -r key; do
318 + git -C "$dir" config --local --unset-all "$key"
319 + done
320 + if git -C "$dir" config --local --get-regexp 'extraheader|includeif'; then
321 + echo "::error::checkout credentials are still configured in $dir"
322 + exit 1
323 + fi
324 + done
325 + rm -f "$RUNNER_TEMP"/git-credentials-*.config
326 + if ls "$RUNNER_TEMP"/git-credentials-*.config 2>/dev/null; then
327 + echo "::error::a checkout credential file is still present"
328 + exit 1
329 + fi
330 +
331 + - name: Prepare build directories
332 + if: steps.record.outputs.built != 'true'
333 + run: |
334 + cache="$HOME/.cache/t3-android-preview"
335 + {
336 + echo "GRADLE_USER_HOME=$cache/gradle"
337 + echo "CCACHE_DIR=$cache/ccache"
338 + echo "CCACHE_MAXSIZE=5G"
339 + # Gradle installs the NDK fresh each run, so key on the compiler's version, not its mtime.
340 + echo "CCACHE_COMPILERCHECK=%compiler% -v"
341 + echo "pnpm_config_store_dir=$cache/pnpm-store"
342 + # eas build --local copies the project here. A fixed path keeps
343 + # ccache keys stable, and the same disk as the store lets pnpm hardlink.
344 + echo "EAS_LOCAL_BUILD_WORKINGDIR=$cache/eas-build"
345 + echo "CCACHE_BASEDIR=$cache/eas-build"
346 + echo "CMAKE_C_COMPILER_LAUNCHER=ccache"
347 + echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache"
348 + } >> "$GITHUB_ENV"
349 +
350 + - name: Mount build cache
351 + if: steps.record.outputs.built != 'true'
352 + uses: useblacksmith/stickydisk@v1
353 + with:
354 + key: ${{ github.repository }}-android-preview-build
355 + path: ~/.cache/t3-android-preview
356 +
357 + - name: Configure Gradle and ccache
358 + if: steps.record.outputs.built != 'true'
359 + run: |
360 + mkdir -p "$GRADLE_USER_HOME" "$CCACHE_DIR"
361 + rm -rf "$EAS_LOCAL_BUILD_WORKINGDIR"
362 + # No daemon: nothing should hold the sticky disk open when it is committed.
363 + printf 'org.gradle.caching=true\norg.gradle.daemon=false\n' > "$GRADLE_USER_HOME/gradle.properties"
364 + sudo sed -i 's|http://|https://|g' /etc/apt/blacksmith-ubuntu-mirrors.txt /etc/apt/sources.list.d/ubuntu.sources
365 + sudo apt-get update -qq && sudo apt-get install -y -qq ccache
366 + ccache --zero-stats
367 +
368 + - name: Setup Node
369 + if: steps.record.outputs.built != 'true'
370 + uses: actions/setup-node@v6
371 + with:
372 + node-version-file: package.json
373 +
374 + - name: Enable corepack
375 + if: steps.record.outputs.built != 'true'
376 + run: |
377 + npm install --global corepack@latest
378 + corepack enable
379 + pnpm --version
380 +
381 + - name: Install mobile dependencies
382 + if: steps.record.outputs.built != 'true'
383 + run: pnpm install --frozen-lockfile --prefer-offline --filter=@t3tools/mobile...
384 +
385 + - name: Setup Java
386 + if: steps.record.outputs.built != 'true'
387 + uses: actions/setup-java@v5
388 + with:
389 + distribution: temurin
390 + java-version: 17
391 +
392 + - name: Setup EAS
393 + if: steps.record.outputs.built != 'true'
394 + uses: expo/expo-github-action@v8
395 + with:
396 + eas-version: latest
397 + token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
398 + packager: npm
399 +
400 + - name: Pull preview environment variables
401 + if: steps.record.outputs.built != 'true'
402 + working-directory: apps/mobile
403 + run: |
404 + eas env:pull preview --non-interactive
405 + node --input-type=module <<'NODE'
406 + import { appendFileSync, readFileSync } from "node:fs";
407 + import { parseEnv } from "node:util";
408 + const env = parseEnv(readFileSync(".env.local", "utf8"));
409 + const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
410 + if (googleServicesFile) {
411 + appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
412 + }
413 + NODE
414 +
415 + # `eas upload` hosts the APK on EAS and returns the page testers install from.
416 + - id: build
417 + name: Build and upload
418 + if: steps.record.outputs.built != 'true'
419 + working-directory: apps/mobile
420 + shell: bash
421 + run: |
422 + eas build --local --platform android --profile preview:dev --non-interactive --output "$RUNNER_TEMP/t3code-preview.apk"
423 + eas upload --platform android --build-path "$RUNNER_TEMP/t3code-preview.apk" --fingerprint "$FINGERPRINT" --non-interactive --json | tee "$RUNNER_TEMP/upload.json"
424 + link="$(sed -n '/^{/,$p' "$RUNNER_TEMP/upload.json" | jq -r '.url // empty')"
425 + if [ -z "$link" ]; then
426 + echo "::error::eas upload returned no install link"
427 + exit 1
428 + fi
429 + echo "link=$link" >> "$GITHUB_OUTPUT"
430 + {
431 + echo "### Android preview client for \`$FINGERPRINT\`: $link"
432 + echo '```'
433 + ccache --show-stats
434 + echo '```'
435 + } >> "$GITHUB_STEP_SUMMARY"
436 +
437 + # The tag is the record later runs look up; its message is the install link.
438 + - name: Record build
439 + if: steps.record.outputs.built != 'true'
440 + env:
441 + LINK: ${{ steps.build.outputs.link }}
442 + GH_TOKEN: ${{ github.token }}
443 + run: |
444 + git config user.name "github-actions[bot]"
445 + git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
446 + git tag -a "$BUILD_TAG" -m "$LINK"
447 + # Only this step has the token; the checkout's copy was removed before the build.
448 + git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "refs/tags/$BUILD_TAG"
449 +
450 + - name: Comment
451 + env:
452 + GH_TOKEN: ${{ github.token }}
453 + PR: ${{ github.event.pull_request.number }}
454 + CLIENT: ${{ steps.build.outputs.link || steps.record.outputs.link }}
455 + run: node .github/scripts/mobile-preview-comment.cjs