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