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