@@ -147,13 +147,45 @@ jobs:
147147 run : ' test -z "$(git status --porcelain "docs-shopify.dev/generated/*.json" )" || { echo -e "Run (pnpm build-dev-docs) before pushing new commands or flags." ; exit 1; }'
148148
149149 unit-tests :
150- name : ' Unit tests with Node ${{ matrix.node }} in ${{ matrix.os }}'
150+ name : " Unit tests with Node ${{ matrix.node }} in ${{ matrix.os }}${{ matrix.shard != '' && format(' (shard {0})', matrix.shard) || '' }} "
151151 runs-on : ${{ matrix.os }}
152152 timeout-minutes : 30
153153 strategy :
154154 matrix :
155155 os : [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
156156 node : [ '20.14.0', '22.2.0', '24.1.0' ]
157+ shard : [ '' ]
158+ include :
159+ # Add sharding for Windows jobs to reduce wall-clock time
160+ - os : windows-latest
161+ node : ' 20.14.0'
162+ shard : ' 1/2'
163+ - os : windows-latest
164+ node : ' 20.14.0'
165+ shard : ' 2/2'
166+ - os : windows-latest
167+ node : ' 22.2.0'
168+ shard : ' 1/2'
169+ - os : windows-latest
170+ node : ' 22.2.0'
171+ shard : ' 2/2'
172+ - os : windows-latest
173+ node : ' 24.1.0'
174+ shard : ' 1/2'
175+ - os : windows-latest
176+ node : ' 24.1.0'
177+ shard : ' 2/2'
178+ exclude :
179+ # Exclude the non-sharded Windows entries (replaced by sharded ones above)
180+ - os : windows-latest
181+ node : ' 20.14.0'
182+ shard : ' '
183+ - os : windows-latest
184+ node : ' 22.2.0'
185+ shard : ' '
186+ - os : windows-latest
187+ node : ' 24.1.0'
188+ shard : ' '
157189 steps :
158190 - uses : actions/checkout@v3
159191 with :
@@ -165,16 +197,30 @@ jobs:
165197 with :
166198 node-version : ${{ matrix.node }}
167199 - name : Unit tests
168- run : pnpm vitest run
200+ run : pnpm vitest run ${{ matrix.shard && format('--shard {0}', matrix.shard) || '' }}
169201 env :
170202 VITEST_MIN_THREADS : " 1"
171203 VITEST_MAX_THREADS : " 4"
172204
173- test-coverage :
205+ unit-tests-gate :
206+ name : " Unit tests"
207+ needs : unit-tests
208+ if : always()
209+ runs-on : ubuntu-latest
210+ timeout-minutes : 5
211+ steps :
212+ - name : Verify all unit tests passed
213+ if : needs.unit-tests.result != 'success'
214+ run : exit 1
215+
216+ test-coverage-shard :
174217 if : ${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
175- name : ' Test Coverage'
218+ name : " Test Coverage (shard ${{ matrix.shard }}) "
176219 runs-on : ubuntu-latest
177220 timeout-minutes : 30
221+ strategy :
222+ matrix :
223+ shard : ['1/2', '2/2']
178224 steps :
179225 - uses : actions/checkout@v3
180226 with :
@@ -185,12 +231,54 @@ jobs:
185231 uses : ./.github/actions/setup-cli-deps
186232 with :
187233 node-version : ${{ env.DEFAULT_NODE_VERSION }}
188- - name : Build
189- run : pnpm nx run-many --all --skip-nx-cache --target=build --output-style=stream
190- - name : Run and save test coverage
191- uses : ./.github/actions/run-and-save-test-coverage
234+ - name : Unit tests with coverage (shard)
235+ run : pnpm vitest run --coverage --coverage.all=false --reporter=blob --outputFile=vitest-blob-reports/blob-${{ matrix.shard == '1/2' && '1' || '2' }}.json --shard ${{ matrix.shard }}
236+ env :
237+ VITEST_MIN_THREADS : " 1"
238+ VITEST_MAX_THREADS : " 4"
239+ - uses : actions/upload-artifact@v4
240+ with :
241+ name : coverage-blob-${{ matrix.shard == '1/2' && '1' || '2' }}
242+ path : vitest-blob-reports/
243+ retention-days : 1
244+
245+ test-coverage-merge :
246+ if : ${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
247+ needs : test-coverage-shard
248+ name : ' Test Coverage'
249+ runs-on : ubuntu-latest
250+ timeout-minutes : 15
251+ steps :
252+ - uses : actions/checkout@v3
253+ with :
254+ repository : ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}
255+ ref : ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
256+ fetch-depth : 1
257+ - name : Setup deps
258+ uses : ./.github/actions/setup-cli-deps
259+ with :
260+ node-version : ${{ env.DEFAULT_NODE_VERSION }}
261+ - uses : actions/download-artifact@v4
262+ with :
263+ pattern : coverage-blob-*
264+ path : vitest-blob-reports
265+ merge-multiple : true
266+ - name : Merge coverage reports
267+ run : pnpm vitest --mergeReports vitest-blob-reports --reporter=json --outputFile=./coverage/report.json --coverage --coverage.all=false
268+ - name : Convert coverage to Jest
269+ run : ./bin/save-coverage-file.js
270+ - name : Take copy of report as new baseline for branch
271+ run : cp ./report.json ./baseline-report.json
272+ - name : Clean ref name
273+ env :
274+ SAFE_REF_NAME : " ${{ github.head_ref }}"
275+ run : |
276+ SAFE_REF_NAME="${SAFE_REF_NAME//[\/.]/}"
277+ echo "SAFE_REF_NAME=${SAFE_REF_NAME}" >> $GITHUB_ENV
278+ - uses : actions/upload-artifact@v4
192279 with :
193- branch-name : ' ${{ github.head_ref }}'
280+ name : ${{ env.SAFE_REF_NAME }}--coverage-report
281+ path : ./baseline-report.json
194282 - name : Download and publish test coverage
195283 uses : ./.github/actions/download-and-publish-test-coverage
196284 with :
0 commit comments