@@ -2,10 +2,10 @@ name: Fork tests
22
33# Fork only. Upstream's CI checks (ci.yml) on GitHub-hosted runners, because the
44# fork has none of upstream's runners and upstream's workflows are disabled here.
5- # Commands follow ci.yml step for step; only the runners, time limits, apt
6- # setup, the task cache (kept with actions/cache instead of upstream's private
7- # remote cache) and the Test job's split across two runners differ. Upstream's
8- # composite actions and change detector (.github/actions,
5+ # Commands follow ci.yml step for step. Only the runners, time limits, apt
6+ # setup and the task cache differ (kept with actions/cache instead of upstream's
7+ # private remote cache), and Test and Test Web split over two runners each.
8+ # Upstream's composite actions and change detector (.github/actions,
99# .github/scripts/ci-changes.cjs) are used as they are, so a rebase brings their
1010# changes. The `workflows` job lints the fork workflows (actionlint) and fails
1111# when upstream's ci.yml or release.yml test jobs change and this copy did not
@@ -14,8 +14,8 @@ name: Fork tests
1414# Require only `fork-ci-result` in a ruleset: it needs every other job, so jobs
1515# can be added, split or resharded without touching the ruleset.
1616#
17- # Runners: GitHub-hosted only, Ubuntu 24.04 as upstream (ubuntu-latest is now
18- # 26.04, whose newer git fails an apps/server test upstream never sees) . Never
17+ # Runners: GitHub-hosted only, Ubuntu 24.04 like upstream's runners, so an OS
18+ # upgrade is a reviewed change here, not a surprise from ubuntu-latest . Never
1919# add a self-hosted runner to this workflow: this repository is public, so a
2020# pull request from any fork would run its code on that machine.
2121#
@@ -403,9 +403,9 @@ jobs:
403403 exit "$(cat "$RUNNER_TEMP/typecheck-status")"
404404
405405 # Everything except `t3` (apps/server) and the web app, which have their own jobs.
406- # Upstream runs this on one large runner. Here the packages are split across
407- # two 4-CPU runners by test file count (.github/scripts/fork-test-shards.cjs);
408- # one runner took 6 minutes, the longest job of the run .
406+ # Upstream runs this on one large runner; one 4-CPU runner took 6 minutes.
407+ # Two runners split it (.github/scripts/fork-test-shards.cjs): each runs a
408+ # vitest slice of every large package and half of the others, whole .
409409 test :
410410 name : Test ${{ matrix.shard }}
411411 needs : changes
@@ -427,20 +427,21 @@ jobs:
427427 !/apps/mobile/modules/t3-terminal/Vendor/**/*.a
428428 sparse-checkout-cone-mode : false
429429
430- # Shard 1 always gets the heaviest affected package; a shard left with
431- # none says so in the summary and stops here.
430+ # A shard with nothing to run says so in the summary and stops here.
432431 - name : Pick this shard's packages
433432 id : shard
434433 env :
435434 TEST_PACKAGES : ${{ needs.changes.outputs.test_packages }}
436435 run : |
437- packages=$(node .github/scripts/fork-test-shards.cjs "${{ matrix.shard }}/${{ strategy.job-total }}" | tr '\n' ' ')
438- echo "packages=${packages% }" >> "$GITHUB_OUTPUT"
436+ work=$(node .github/scripts/fork-test-shards.cjs "${{ matrix.shard }}/${{ strategy.job-total }}")
437+ whole=$(awk '$1 == "whole" { printf "%s ", $2 }' <<< "$work")
438+ split=$(awk '$1 == "split" { printf "%s ", $2 }' <<< "$work")
439+ { echo "whole=${whole% }"; echo "split=${split% }"; echo "any=$([[ -n "$work" ]] && echo true || echo false)"; } >> "$GITHUB_OUTPUT"
439440
440441 # The desktop tests compile the browser secret helper. The install runs in
441442 # the background while Vite+ installs; the step before the tests waits for it.
442443 - name : Start installing browser secret helper build libraries
443- if : steps.shard.outputs.packages != ' '
444+ if : steps.shard.outputs.any == 'true '
444445 run : |
445446 (
446447 set +e
@@ -452,21 +453,21 @@ jobs:
452453 ) > "$RUNNER_TEMP/apt.log" 2>&1 < /dev/null &
453454
454455 - name : Setup Vite+
455- if : steps.shard.outputs.packages != ' '
456+ if : steps.shard.outputs.any == 'true '
456457 uses : ./.github/actions/setup-ci-deps
457458 with :
458459 # Lint saves the pnpm store; the others only restore it.
459460 save-pnpm-store : false
460461
461462 - name : Cache Electron download
462- if : steps.shard.outputs.packages != ' '
463+ if : steps.shard.outputs.any == 'true '
463464 uses : actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
464465 with :
465466 path : ~/.cache/electron
466467 key : electron-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('node_modules/.pnpm/electron@*/node_modules/electron/package.json') }}
467468
468469 - name : Ensure Electron runtime is installed
469- if : steps.shard.outputs.packages != ' '
470+ if : steps.shard.outputs.any == 'true '
470471 run : vp run --filter @t3tools/desktop ensure:electron
471472
472473 - name : Test preview artifact validation
@@ -478,34 +479,58 @@ jobs:
478479 run : node --test .github/scripts/check-nightly-release.test.cjs .github/scripts/vercel-deployment-output.test.cjs .github/scripts/mobile-preview-comment.test.cjs
479480
480481 - name : Finish installing browser secret helper build libraries
481- if : steps.shard.outputs.packages != ' '
482+ if : steps.shard.outputs.any == 'true '
482483 timeout-minutes : 5
483484 run : |
484485 until test -s "$RUNNER_TEMP/apt-status"; do sleep 1; done
485486 cat "$RUNNER_TEMP/apt.log"
486487 exit "$(cat "$RUNNER_TEMP/apt-status")"
487488
489+ # Whole packages as upstream runs them; a large package's slice runs its
490+ # own test script in its directory with vitest's --shard (`vp run` does
491+ # not pass arguments through to vitest).
488492 - name : Test
489- if : steps.shard.outputs.packages != ' '
493+ if : steps.shard.outputs.any == 'true '
490494 env :
491- PACKAGES : ${{ steps.shard.outputs.packages }}
495+ WHOLE : ${{ steps.shard.outputs.whole }}
496+ SPLIT : ${{ steps.shard.outputs.split }}
497+ SHARD : ${{ matrix.shard }}/${{ strategy.job-total }}
492498 run : |
493499 set -o pipefail
494- filters=()
495- for package in $PACKAGES; do filters+=(--filter "$package"); done
496500 # The runner's trace writer can crash on surrogate pairs in test output.
497- vp run --parallel --concurrency-limit 4 "${filters[@]}" test 2>&1 | python3 -u -c '
501+ ascii() {
502+ python3 -u -c '
498503 import sys
499504 for line in sys.stdin:
500505 sys.stdout.write(line.encode("ascii", "backslashreplace").decode("ascii"))
501506 '
507+ }
508+ status=0
509+ if [[ -n "$WHOLE" ]]; then
510+ filters=()
511+ for package in $WHOLE; do filters+=(--filter "$package"); done
512+ vp run --parallel --concurrency-limit 4 "${filters[@]}" test 2>&1 | ascii || status=1
513+ fi
514+ for dir in $SPLIT; do
515+ echo "::group::$dir slice $SHARD"
516+ script=$(jq -r .scripts.test "$dir/package.json")
517+ (cd "$dir" && eval "$script --shard=$SHARD") 2>&1 | ascii || status=1
518+ echo "::endgroup::"
519+ done
520+ exit "$status"
502521
522+ # Upstream runs this on one large runner; on a 4-CPU runner the 548 files
523+ # took 7.5 minutes, so two runners each take a vitest slice.
503524 test_web :
504- name : Test Web
525+ name : Test Web ${{ matrix.shard }}
505526 needs : changes
506527 if : ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }}
507528 runs-on : ubuntu-24.04
508529 timeout-minutes : 15
530+ strategy :
531+ fail-fast : false
532+ matrix :
533+ shard : [1, 2]
509534 steps :
510535 - name : Checkout
511536 uses : actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
@@ -546,8 +571,13 @@ jobs:
546571 node apps/web/node_modules/playwright/cli.js install-deps chromium
547572 fi
548573
574+ # Upstream: `vp run --filter @t3tools/web test`. Same script, run in its
575+ # directory, because `vp run` does not pass --shard through to vitest.
549576 - name : Test
550- run : vp run --filter @t3tools/web test
577+ env :
578+ SHARD : ${{ matrix.shard }}/${{ strategy.job-total }}
579+ working-directory : apps/web
580+ run : eval "$(jq -r .scripts.test package.json) --shard=$SHARD"
551581
552582 # apps/server runs its test files one at a time; shards spread them over
553583 # separate runners. The shards gate themselves instead of waiting for
@@ -802,6 +832,8 @@ jobs:
802832 RELEASE_RUN : ${{ inputs.ref != '' }}
803833 run : |
804834 echo "$RESULTS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"'
835+ # A jq program: $release is jq's variable, not the shell's.
836+ # shellcheck disable=SC2016
805837 why='{
806838 build: "the change affects neither desktop, server nor web, and no package needs a typecheck",
807839 test: "the change affects no package this job tests",
0 commit comments