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

mobile-eas-preview.yml

317 lines13.5 KB

1name: Mobile EAS Preview
2​
3on:
4 pull_request:
5 types: [opened, reopened, synchronize, labeled]
6​
7permissions:
8 contents: read
9​
10jobs:
11 ios:
12 name: EAS Preview (iOS)
13 if: |
14 github.event.pull_request.head.repo.full_name == github.repository &&
15 contains(github.event.pull_request.labels.*.name, '🚀 Mobile Continuous Deployment') &&
16 (github.event.action != 'labeled' || github.event.label.name == '🚀 Mobile Continuous Deployment')
17 runs-on: blacksmith-8vcpu-ubuntu-2404
18 concurrency:
19 group: mobile-eas-preview-ios-${{ github.event.pull_request.number }}
20 cancel-in-progress: true
21 permissions:
22 contents: read
23 outputs:
24 group: ${{ steps.update.outputs.group }}
25 client: ${{ steps.client.outputs.link }}
26 build: ${{ steps.client.outputs.build }}
27 fingerprint: ${{ steps.client.outputs.fingerprint }}
28 env:
29 APP_VARIANT: preview
30 NODE_OPTIONS: --max-old-space-size=8192
31 MOBILE_VERSION_POLICY: fingerprint
32 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
33 GH_TOKEN: ${{ github.token }}
34 PR: ${{ github.event.pull_request.number }}
35 steps:
36 - id: expo-token
37 name: Check for EXPO_PREVIEW_TOKEN
38 run: |
39 if [ -n "$EXPO_TOKEN" ]; then
40 echo "present=true" >> "$GITHUB_OUTPUT"
41 else
42 echo "present=false" >> "$GITHUB_OUTPUT"
43 echo "EXPO_PREVIEW_TOKEN is not available; skipping the iOS preview."
44 fi
45​
46 - name: Checkout
47 if: steps.expo-token.outputs.present == 'true'
48 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
49 with:
50 fetch-depth: 0
51​
52 # The steps below run dependency and build scripts; they get no token.
53 - name: Drop checkout credentials
54 if: steps.expo-token.outputs.present == 'true'
55 uses: ./.github/actions/drop-checkout-credentials
56​
57 - name: Setup Vite+
58 if: steps.expo-token.outputs.present == 'true'
59 uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
60 with:
61 node-version-file: package.json
62 cache: true
63 run-install: |
64 args:
65 - --filter=@t3tools/mobile...
66​
67 - name: Expose pnpm
68 if: steps.expo-token.outputs.present == 'true'
69 run: |
70 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
71 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
72 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
73 "$vp_pnpm_bin/pnpm" --version
74​
75 - name: Setup EAS
76 if: steps.expo-token.outputs.present == 'true'
77 uses: expo/expo-github-action@c7b66a9c327a43a8fa7c0158e7f30d6040d2481e # v8.2.1
78 with:
79 eas-version: latest
80 token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
81 packager: npm
82​
83 - name: Pull preview environment variables
84 if: steps.expo-token.outputs.present == 'true'
85 working-directory: apps/mobile
86 run: |
87 eas env:pull preview --non-interactive
88 node --input-type=module <<'NODE'
89 import { appendFileSync, readFileSync } from "node:fs";
90 import { parseEnv } from "node:util";
91 const env = parseEnv(readFileSync(".env.local", "utf8"));
92 const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
93 if (googleServicesFile) {
94 appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
95 }
96 NODE
97​
98 # The same command the Expo action runs, so this is the runtime version the update gets.
99 - id: client
100 name: Find the client for this fingerprint
101 if: steps.expo-token.outputs.present == 'true'
102 working-directory: apps/mobile
103 shell: bash
104 run: |
105 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)')"
106 echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
107 tag="mobile-ios-preview-build/$hash"
108 link=""
109 if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
110 link="$(git tag -l --format='%(contents)' "$tag" | node "$GITHUB_WORKSPACE/.github/scripts/mobile-ios-preview-record.cjs" read)"
111 fi
112 if [ -z "$link" ]; then
113 # A client EAS built before this job existed; expired ones are gone.
114 link="$(eas build:list --platform ios --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
115 | sed -n '/^\[/,$p' \
116 | 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)"')"
117 fi
118 echo "link=$link" >> "$GITHUB_OUTPUT"
119 if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
120 echo "ios fingerprint \`$hash\`: ${link:-no client yet, building on Blacksmith}" >> "$GITHUB_STEP_SUMMARY"
121​
122 - id: update
123 name: Publish the update
124 if: steps.expo-token.outputs.present == 'true'
125 working-directory: apps/mobile
126 shell: bash
127 run: |
128 group="$(eas update --auto --branch "pr-$PR" --platform ios --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
129 echo "group=$group" >> "$GITHUB_OUTPUT"
130​
131 # Preview build tags store the install link for each fingerprint; older EAS clients also count.
132 android:
133 name: EAS Preview (Android)
134 if: |
135 github.event.pull_request.head.repo.full_name == github.repository &&
136 contains(github.event.pull_request.labels.*.name, '🚀 Mobile Continuous Deployment') &&
137 (github.event.action != 'labeled' || github.event.label.name == '🚀 Mobile Continuous Deployment')
138 runs-on: blacksmith-8vcpu-ubuntu-2404
139 concurrency:
140 group: mobile-eas-preview-android-${{ github.event.pull_request.number }}
141 cancel-in-progress: true
142 permissions:
143 contents: read
144 outputs:
145 group: ${{ steps.update.outputs.group }}
146 client: ${{ steps.client.outputs.link }}
147 build: ${{ steps.client.outputs.build }}
148 fingerprint: ${{ steps.client.outputs.fingerprint }}
149 env:
150 APP_VARIANT: preview
151 NODE_OPTIONS: --max-old-space-size=8192
152 MOBILE_VERSION_POLICY: fingerprint
153 EXPO_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
154 GH_TOKEN: ${{ github.token }}
155 PR: ${{ github.event.pull_request.number }}
156 steps:
157 - id: expo-token
158 name: Check for EXPO_PREVIEW_TOKEN
159 run: |
160 if [ -n "$EXPO_TOKEN" ]; then
161 echo "present=true" >> "$GITHUB_OUTPUT"
162 else
163 echo "present=false" >> "$GITHUB_OUTPUT"
164 echo "EXPO_PREVIEW_TOKEN is not available; skipping the Android preview."
165 fi
166​
167 - name: Checkout
168 if: steps.expo-token.outputs.present == 'true'
169 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
170 with:
171 fetch-depth: 0
172​
173 # The steps below run dependency and build scripts; they get no token.
174 - name: Drop checkout credentials
175 if: steps.expo-token.outputs.present == 'true'
176 uses: ./.github/actions/drop-checkout-credentials
177​
178 - name: Setup Vite+
179 if: steps.expo-token.outputs.present == 'true'
180 uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
181 with:
182 node-version-file: package.json
183 cache: true
184 run-install: |
185 args:
186 - --filter=@t3tools/mobile...
187​
188 - name: Expose pnpm
189 if: steps.expo-token.outputs.present == 'true'
190 run: |
191 pnpm_version="$(node --print "require('./package.json').packageManager.split('@').pop()")"
192 vp_pnpm_bin="$HOME/.vite-plus/package_manager/pnpm/$pnpm_version/pnpm/bin"
193 echo "$vp_pnpm_bin" >> "$GITHUB_PATH"
194 "$vp_pnpm_bin/pnpm" --version
195​
196 - name: Setup EAS
197 if: steps.expo-token.outputs.present == 'true'
198 uses: expo/expo-github-action@c7b66a9c327a43a8fa7c0158e7f30d6040d2481e # v8.2.1
199 with:
200 eas-version: latest
201 token: ${{ secrets.EXPO_PREVIEW_TOKEN }}
202 packager: npm
203​
204 - name: Pull preview environment variables
205 if: steps.expo-token.outputs.present == 'true'
206 working-directory: apps/mobile
207 run: |
208 eas env:pull preview --non-interactive
209 node --input-type=module <<'NODE'
210 import { appendFileSync, readFileSync } from "node:fs";
211 import { parseEnv } from "node:util";
212 const env = parseEnv(readFileSync(".env.local", "utf8"));
213 const googleServicesFile = env.T3CODE_ANDROID_GOOGLE_SERVICES_FILE;
214 if (googleServicesFile) {
215 appendFileSync(process.env.GITHUB_ENV, `T3CODE_ANDROID_GOOGLE_SERVICES_FILE=${googleServicesFile}\n`);
216 }
217 NODE
218​
219 # The same command the Expo action runs, so this is the runtime version the update gets.
220 - id: client
221 name: Find the client for this fingerprint
222 if: steps.expo-token.outputs.present == 'true'
223 working-directory: apps/mobile
224 shell: bash
225 run: |
226 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)')"
227 echo "fingerprint=$hash" >> "$GITHUB_OUTPUT"
228 tag="mobile-android-preview-build/$hash"
229 link=""
230 if git fetch --quiet origin "refs/tags/$tag:refs/tags/$tag" 2>/dev/null; then
231 link="$(git tag -l --format='%(contents:subject)' "$tag")"
232 else
233 # A client EAS built before this job existed; expired ones are gone.
234 link="$(eas build:list --platform android --build-profile preview:dev --runtime-version "$hash" --status finished --limit 5 --json --non-interactive \
235 | sed -n '/^\[/,$p' \
236 | 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)"')"
237 fi
238 echo "link=$link" >> "$GITHUB_OUTPUT"
239 if [ -z "$link" ]; then echo "build=true" >> "$GITHUB_OUTPUT"; fi
240 echo "android fingerprint \`$hash\`: ${link:-no client yet, building on Blacksmith}" >> "$GITHUB_STEP_SUMMARY"
241​
242 - id: update
243 name: Publish the update
244 if: steps.expo-token.outputs.present == 'true'
245 working-directory: apps/mobile
246 shell: bash
247 run: |
248 group="$(eas update --auto --branch "pr-$PR" --platform android --environment preview --non-interactive --json | sed -n '/^\[/,$p' | jq -er '.[0].group')"
249 echo "group=$group" >> "$GITHUB_OUTPUT"
250​
251 # Each build runs in mobile-eas-preview-build.yml, whose record job alone gets
252 # the token that pushes the tag. The group covers both of its jobs.
253 android-build:
254 name: Android preview client
255 needs: android
256 if: needs.android.outputs.build == 'true'
257 concurrency:
258 # One build per fingerprint; a second PR with the same one finds the tag.
259 group: mobile-android-preview-build-${{ needs.android.outputs.fingerprint }}
260 cancel-in-progress: false
261 queue: max
262 permissions:
263 contents: write # the record job pushes the build record tag
264 uses: ./.github/workflows/mobile-eas-preview-build.yml
265 with:
266 platform: android
267 fingerprint: ${{ needs.android.outputs.fingerprint }}
268 secrets:
269 EXPO_PREVIEW_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
270​
271 ios-build:
272 name: iOS preview client
273 needs: ios
274 if: needs.ios.outputs.build == 'true'
275 concurrency:
276 # One build per fingerprint; a second PR with the same one finds the tag.
277 group: mobile-ios-preview-build-${{ needs.ios.outputs.fingerprint }}
278 cancel-in-progress: false
279 queue: max
280 permissions:
281 contents: write # the record job pushes the build record tag
282 uses: ./.github/workflows/mobile-eas-preview-build.yml
283 with:
284 platform: ios
285 fingerprint: ${{ needs.ios.outputs.fingerprint }}
286 secrets:
287 EXPO_PREVIEW_TOKEN: ${{ secrets.EXPO_PREVIEW_TOKEN }}
288​
289 comment:
290 name: Mobile preview comment
291 needs: [android, ios, android-build, ios-build]
292 if: always() && !cancelled() && (needs.android.result == 'success' || needs.ios.result == 'success')
293 runs-on: blacksmith-2vcpu-ubuntu-2404
294 concurrency:
295 group: mobile-preview-comment-${{ github.event.pull_request.number }}
296 cancel-in-progress: false
297 permissions:
298 contents: read
299 pull-requests: write
300 steps:
301 - name: Checkout comment script
302 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
303 with:
304 sparse-checkout: .github/scripts
305​
306 - name: Comment
307 env:
308 GH_TOKEN: ${{ github.token }}
309 PR: ${{ github.event.pull_request.number }}
310 PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
311 ANDROID_FINGERPRINT: ${{ needs.android.outputs.fingerprint }}
312 ANDROID_GROUP: ${{ needs.android.outputs.group }}
313 ANDROID_CLIENT: ${{ needs.android-build.outputs.client || needs.android.outputs.client }}
314 IOS_FINGERPRINT: ${{ needs.ios.outputs.fingerprint }}
315 IOS_GROUP: ${{ needs.ios.outputs.group }}
316 IOS_CLIENT: ${{ needs.ios-build.outputs.client || needs.ios.outputs.client }}
317 run: node .github/scripts/mobile-preview-comment.cjs