77 paths-ignore :
88 - ' compiler/**'
99
10+ env :
11+ # Number of workers (one per shard) to spawn
12+ SHARD_COUNT : 5
13+
1014jobs :
1115 # Define the various test parameters and parallelism for this workflow
1216 build_test_params :
1317 name : Build test params
1418 runs-on : ubuntu-latest
1519 outputs :
1620 params : ${{ steps.define-params.outputs.result }}
17- # How many chunks to group tests into
18- parallelism : 5
21+ shard_id : ${{ steps.define-chunks.outputs.result }}
1922 steps :
23+ - uses : actions/github-script@v7
24+ id : define-chunks
25+ with :
26+ script : |
27+ function range(from, to) {
28+ const arr = [];
29+ for (let n = from; n < to; n++) {
30+ arr.push(n);
31+ }
32+ return arr;
33+ }
34+ return range(0, process.env.SHARD_COUNT);
2035 - uses : actions/github-script@v7
2136 id : define-params
2237 with :
@@ -43,51 +58,15 @@ jobs:
4358 "-r=experimental --env=development --persistent"
4459 ];
4560
46- # Chunk tests into groups for parallelism
47- chunk_tests :
48- name : Chunk tests
49- runs-on : ubuntu-latest
50- needs : build_test_params
51- strategy :
52- matrix :
53- params : ${{ fromJSON(needs.build_test_params.outputs.params) }}
54- continue-on-error : true
55- outputs :
56- chunks : ${{ steps.chunks.outputs.chunks }}
57- chunk_ids : ${{ steps.chunk_ids.outputs.chunk_ids }}
58- steps :
59- - uses : actions/checkout@v4
60- - uses : actions/setup-node@v4
61- with :
62- node-version : 18.x
63- cache : " yarn"
64- cache-dependency-path : yarn.lock
65- - name : Restore cached node_modules
66- uses : actions/cache@v4
67- id : node_modules
68- with :
69- path : " **/node_modules"
70- key : ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
71- - run : yarn install --frozen-lockfile
72- - id : chunks
73- name : Set chunks
74- run : echo "chunks=$(yarn --silent test ${{ matrix.params }} --listTests --json --ci=github | jq -cM '[_nwise(length / ${{ needs.build_test_params.outputs.parallelism }} | ceil)]')" >> $GITHUB_OUTPUT
75- - id : chunk_ids
76- name : Set chunk IDs
77- run : echo "chunk_ids=$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')" >> $GITHUB_OUTPUT
78- env :
79- CHUNKS : ${{ steps.chunks.outputs.chunks }}
80-
81- # Spawn a job for each set of test param and number of chunks
61+ # Spawn a job for each shard for a given set of test params
8262 test :
83- name : yarn test ${{ matrix.params }} (Chunk ${{ matrix.chunk_ids }})
63+ name : yarn test ${{ matrix.params }} (Chunk ${{ matrix.shard_id }})
8464 runs-on : ubuntu-latest
85- needs : [ build_test_params, chunk_tests]
65+ needs : build_test_params
8666 strategy :
8767 matrix :
8868 params : ${{ fromJSON(needs.build_test_params.outputs.params) }}
89- chunks : ${{ fromJSON(needs.chunk_tests.outputs.chunks) }}
90- chunk_ids : ${{ fromJSON(needs.chunk_tests.outputs.chunk_ids) }}
69+ shard_id : ${{ fromJSON(needs.build_test_params.outputs.shard_id) }}
9170 continue-on-error : true
9271 steps :
9372 - uses : actions/checkout@v4
10382 path : " **/node_modules"
10483 key : ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
10584 - run : yarn install --frozen-lockfile
106- - run : echo $CHUNKS | jq '.[${{ matrix.chunk_ids }}] | .[] | @text' | xargs yarn test ${{ matrix.params }} --ci=github
107- env :
108- CHUNKS : ${{ matrix.chunks }}
85+ - run : yarn test ${{ matrix.params }} --ci=github --shard=${{ matrix.shard_id }}/${{ env.SHARD_COUNT }}
0 commit comments