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

mobile-eas-preview-fork.yml

391 lines16.5 KB

1name: 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; both clients build on Blacksmith
5# 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.
9#
10# Same-repo PRs deploy on every push while labeled, via mobile-eas-preview.yml.
11​
12on:
13 pull_request_target:
14 types: [labeled]
15​
16permissions:
17 contents: read
18​
19jobs:
20 preview:
21 name: EAS Preview
22 if: >-
23 github.event.pull_request.head.repo.full_name != github.repository &&
24 github.event.label.name == '🚀 Mobile Continuous Deployment'
25 runs-on: blacksmith-8vcpu-ubuntu-2404
26 concurrency:
27 group: mobile-eas-preview-fork-${{ github.event.pull_request.number }}
28 cancel-in-progress: true
29 permissions:
30 contents: read
31 pull-requests: write
32 outputs:
33 ios_group: ${{ steps.ios_update.outputs.group }}
34 ios_client: ${{ steps.ios_client.outputs.link }}
35 group: ${{ steps.update.outputs.group }}
36 client: ${{ steps.client.outputs.link }}
37 ios_build: ${{ steps.ios_client.outputs.build }}
38 ios_fingerprint: ${{ steps.ios_client.outputs.fingerprint }}
39 build: ${{ steps.client.outputs.build }}
40 fingerprint: ${{ steps.client.outputs.fingerprint }}
41 env:
42 APP_VARIANT: preview
43 NODE_OPTIONS: --max-old-space-size=8192
44 MOBILE_VERSION_POLICY: fingerprint
45 steps:
46 # The label counts only from someone with write access, who could push a
47 # same-repo branch and get this build anyway. If a maintainer removed the
48 # label first, that removal wins.
49 - id: consume
50 name: Consume the deployment label
51 uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
52 with:
53 script: |
54 try {
55 await github.rest.issues.removeLabel({
56 owner: context.repo.owner,
57 repo: context.repo.repo,
58 issue_number: context.payload.pull_request.number,
59 name: context.payload.label.name,
60 });
61 } catch (error) {
62 if (error.status !== 404) throw error;
63 core.info("The label was removed before this run could consume it. Skipping.");
64 core.setOutput("consumed", "false");
65 return;
66 }
67 const sender = context.payload.sender.login;
68 const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({
69 owner: context.repo.owner,
70 repo: context.repo.repo,
71 username: sender,
72 });
73 const authorized = ["admin", "maintain", "write"].includes(access.permission);
74 if (!authorized) {
75 core.warning(`${sender} has ${access.permission} access; a fork preview needs write access. Label removed, nothing built.`);
76 }
77 core.setOutput("consumed", String(authorized));
78​
79 - id: expo-token
80 name: Check for EXPO_PREVIEW_TOKEN
81 if: steps.consume.outputs.consumed == 'true'
82 env:
83 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
84 run: |
85 if [ -n "$EXPO_TOKEN" ]; then
86 echo "present=true" >> "$GITHUB_OUTPUT"
87 else
88 echo "present=false" >> "$GITHUB_OUTPUT"
89 echo "EXPO_PREVIEW_TOKEN is not set; skipping EAS preview."
90 fi
91​
92 # The head SHA from the label event, not the branch, so a push after the
93 # label cannot swap in unreviewed code. No credentials stay in .git for
94 # the PR's scripts to read.
95 - name: Checkout reviewed commit
96 if: steps.expo-token.outputs.present == 'true'
97 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
98 with:
99 ref: ${{ github.event.pull_request.head.sha }}
100 fetch-depth: 0
101 # No sparse-checkout: see mobile-eas-preview.yml.
102​
103 # Scripts and actions come from main, not from the PR.
104 - name: Checkout trusted scripts
105 if: steps.expo-token.outputs.present == 'true'
106 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
107 with:
108 path: .trusted
109 sparse-checkout: |
110 .github/scripts
111 .github/actions
112​
113 # The steps below run dependency and build scripts; they get no token.
114 - name: Drop checkout credentials
115 if: steps.expo-token.outputs.present == 'true'
116 uses: ./.trusted/.github/actions/drop-checkout-credentials
117​
118 # No caches: pull_request_target saves them under main's scope, where
119 # trusted workflows with other secrets would restore what PR code wrote.
120 - name: Setup Vite+
121 if: steps.expo-token.outputs.present == 'true'
122 uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
123 with:
124 node-version-file: package.json
125 cache: false
126 run-install: |
127 args:
128 - --filter=@t3tools/mobile...
129​
130 - name: Expose pnpm
131 if: steps.expo-token.outputs.present == 'true'
132 run: |
133 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
134 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
135 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
136 "$vp_pnpm_bin/pnpm" --version
137​
138 - name: Setup EAS
139 if: steps.expo-token.outputs.present == 'true'
140 uses: expo/expo-github-action@c7b66a9c327a43a8fa7c0158e7f30d6040d2481e # v8.2.1
141 with:
142 eas-version: latest
143 eas-cache: false
144 token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
145 packager: npm
146​
147 - name: Pull preview environment variables
148 if: steps.expo-token.outputs.present == 'true'
149 working-directory: apps/mobile
150 env:
151 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
152 run: |
153 eas env:pull preview --non-interactive
154 # See mobile-eas-preview.yml: keeps Android build and OTA fingerprints matching.
155 node --input-type=module <<'NODE'
156 import { appendFileSync, readFileSync } from "node:fs";
157 import { parseEnv } from "node:util";
158 const env = parseEnv(readFileSync(".env.local", "utf8"));
159 const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
160 if (googleServicesFile) {
161 appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
162 }
163 NODE
164​
165 - id: ios_client
166 name: Find the iOS client for this fingerprint
167 if: steps.expo-token.outputs.present == 'true'
168 working-directory: apps/mobile
169 shell: bash
170 env:
171 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
172 run: |
173 hash="$(eas env:exec --non-interactive preview "npx expo-updates fingerprint:generate --platform ios" | sed -n '/^{/,$p' | jq -er '.hash | select(type == "string" and length > 0)')"
174 echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
175 tag="mobile-ios-preview-build/$hash"
176 link=""
177 if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
178 link="$(git tag -l --format='%(contents)' "$tag" | node "$GITHUB_WORKSPACE/.trusted/.github/scripts/mobile-ios-preview-record.cjs" read)"
179 fi
180 if [ -z "$link" ]; then
181 link="$(eas build:list --platform ios --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
182 | sed -n '/^\[/,$p' \
183 | 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)"')"
184 fi
185 echo "link=$link" >> "$GITHUB_OUTPUT"
186 if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
187​
188 - id: ios_update
189 name: Publish the iOS update
190 if: steps.expo-token.outputs.present == 'true'
191 working-directory: apps/mobile
192 shell: bash
193 env:
194 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
195 PR: ${{ github.event.pull_request.number }}
196 run: |
197 group="$(eas update --auto --branch "pr-$PR" --platform ios --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
198 echo "group=$group" >> "$GITHUB_OUTPUT"
199​
200 # Android, as in mobile-eas-preview.yml: the same fingerprint command the Expo
201 # action runs. A client built for a same-repo PR (its tag) or by EAS is reused.
202 - id: client
203 name: Find the Android client for this fingerprint
204 if: steps.expo-token.outputs.present == 'true'
205 working-directory: apps/mobile
206 shell: bash
207 env:
208 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
209 run: |
210 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)')"
211 echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
212 tag="mobile-android-preview-build/$hash"
213 link=""
214 if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
215 link="$(git tag -l --format='%(contents:subject)' "$tag")"
216 else
217 link="$(eas build:list --platform android --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
218 | sed -n '/^\[/,$p' \
219 | 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)"')"
220 fi
221 echo "link=$link" >> "$GITHUB_OUTPUT"
222 if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
223​
224 - id: update
225 name: Publish the Android update
226 if: steps.expo-token.outputs.present == 'true'
227 working-directory: apps/mobile
228 shell: bash
229 env:
230 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
231 PR: ${{ github.event.pull_request.number }}
232 run: |
233 group="$(eas update --auto --branch "pr-$PR" --platform android --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
234 echo "group=$group" >> "$GITHUB_OUTPUT"
235​
236 # The reviewed commit's Android client, built cold: no sticky disk, because PR
237 # code could leave Gradle or ccache state that trusted builds would restore, and
238 # no build record tag, so nobody else is served an APK a fork's code built.
239 android-build:
240 name: Android preview client
241 needs: preview
242 if: needs.preview.outputs.build == 'true'
243 runs-on: blacksmith-32vcpu-ubuntu-2404
244 timeout-minutes: 60
245 permissions:
246 contents: read
247 outputs:
248 client: ${{ steps.build.outputs.link }}
249 env:
250 APP_VARIANT: preview
251 NODE_OPTIONS: --max-old-space-size=8192
252 MOBILE_VERSION_POLICY: fingerprint
253 FINGERPRINT: ${{ needs.preview.outputs.fingerprint }}
254 # Phones only: emulators use the development client from the native-client cache.
255 ORG_GRADLE_PROJECT_reactNativeArchitectures: armeabi-v7a,arm64-v8a
256 steps:
257 - name: Checkout reviewed commit
258 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
259 with:
260 ref: ${{ github.event.pull_request.head.sha }}
261 fetch-depth: 0
262​
263 # Scripts and actions come from main, not from the PR.
264 - name: Checkout trusted scripts
265 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
266 with:
267 path: .trusted
268 sparse-checkout: |
269 .github/scripts
270 .github/actions
271​
272 # The steps below run dependency and build scripts; they get no token.
273 - name: Drop checkout credentials
274 uses: ./.trusted/.github/actions/drop-checkout-credentials
275​
276 # Cold: no sticky disk or EAS cache that trusted builds would restore.
277 - name: Build
278 uses: ./.trusted/.github/actions/eas-local-build
279 with:
280 platform: android
281 profile: preview:dev
282 environment: preview
283 expo-token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
284 output: ${{ runner.temp }}/t3code-preview.apk
285 cache: "false"
286​
287 - id: build
288 name: Upload
289 working-directory: apps/mobile
290 shell: bash
291 env:
292 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
293 run: |
294 eas upload --platform android --build-path "$RUNNER_TEMP/t3code-preview.apk" --fingerprint "$FINGERPRINT" --non-interactive --json | tee "$RUNNER_TEMP/upload.json"
295 link="$(sed -n '/^{/,$p' "$RUNNER_TEMP/upload.json" | jq -r '.url // empty')"
296 if [ -z "$link" ]; then
297 echo "::error::eas upload returned no install link"
298 exit 1
299 fi
300 echo "link=$link" >> "$GITHUB_OUTPUT"
301​
302 ios-build:
303 name: iOS preview client
304 needs: preview
305 if: needs.preview.outputs.ios_build == 'true'
306 runs-on: blacksmith-12vcpu-macos-27
307 timeout-minutes: 60
308 permissions:
309 contents: read
310 outputs:
311 client: ${{ steps.build.outputs.link }}
312 env:
313 APP_VARIANT: preview
314 NODE_OPTIONS: --max-old-space-size=8192
315 MOBILE_VERSION_POLICY: fingerprint
316 FINGERPRINT: ${{ needs.preview.outputs.ios_fingerprint }}
317 steps:
318 - name: Checkout reviewed commit
319 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
320 with:
321 ref: ${{ github.event.pull_request.head.sha }}
322 fetch-depth: 0
323​
324 # Scripts and actions come from main, not from the PR.
325 - name: Checkout trusted scripts
326 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
327 with:
328 path: .trusted
329 sparse-checkout: |
330 .github/scripts
331 .github/actions
332​
333 # The steps below run dependency and build scripts; they get no token.
334 - name: Drop checkout credentials
335 uses: ./.trusted/.github/actions/drop-checkout-credentials
336​
337 # Cold: no sticky disk or EAS cache that trusted builds would restore.
338 - name: Build
339 uses: ./.trusted/.github/actions/eas-local-build
340 with:
341 platform: ios
342 profile: preview:dev
343 environment: preview
344 expo-token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
345 output: ${{ runner.temp }}/t3code-preview.ipa
346 cache: "false"
347​
348 - id: build
349 name: Upload
350 working-directory: apps/mobile
351 shell: bash
352 env:
353 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
354 run: |
355 eas upload --platform ios --build-path "$RUNNER_TEMP/t3code-preview.ipa" --fingerprint "$FINGERPRINT" --non-interactive --json | tee "$RUNNER_TEMP/upload.json"
356 link="$(sed -n '/^{/,$p' "$RUNNER_TEMP/upload.json" | jq -r '.url // empty')"
357 if [ -z "$link" ]; then
358 echo "::error::eas upload returned no install link"
359 exit 1
360 fi
361 echo "link=$link" >> "$GITHUB_OUTPUT"
362​
363 comment:
364 name: Mobile preview comment
365 needs: [preview, android-build, ios-build]
366 if: always() && !cancelled() && needs.preview.result == 'success'
367 runs-on: blacksmith-2vcpu-ubuntu-2404
368 concurrency:
369 group: mobile-preview-comment-${{ github.event.pull_request.number }}
370 cancel-in-progress: false
371 permissions:
372 contents: read
373 pull-requests: write
374 steps:
375 - name: Checkout comment script
376 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
377 with:
378 sparse-checkout: .github/scripts
379​
380 - name: Comment
381 env:
382 GH_TOKEN: ${{ github.token }}
383 PR: ${{ github.event.pull_request.number }}
384 PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
385 ANDROID_FINGERPRINT: ${{ needs.preview.outputs.fingerprint }}
386 ANDROID_GROUP: ${{ needs.preview.outputs.group }}
387 ANDROID_CLIENT: ${{ needs.android-build.outputs.client || needs.preview.outputs.client }}
388 IOS_FINGERPRINT: ${{ needs.preview.outputs.ios_fingerprint }}
389 IOS_GROUP: ${{ needs.preview.outputs.ios_group }}
390 IOS_CLIENT: ${{ needs.ios-build.outputs.client || needs.preview.outputs.ios_client }}
391 run: node .github/scripts/mobile-preview-comment.cjs