diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 80c6310c737e89..db051592becf1e 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -35,6 +35,7 @@ jobs: frontend_all_files: ${{ steps.changes.outputs.frontend_all_files }} merge_base: ${{ steps.merge_base.outputs.merge_base }} merge_base_strategy: ${{ steps.merge_base.outputs.merge_base_strategy }} + jest_test_matrix: ${{ steps.jest_matrix_config.outputs.jest_test_matrix }} steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: @@ -74,6 +75,17 @@ jobs: echo "merge_base=${MERGE_BASE:-}" >> "$GITHUB_OUTPUT" echo "merge_base_strategy=${STRATEGY}" >> "$GITHUB_OUTPUT" + - name: Jest Matrix Config + id: jest_matrix_config + run: | + RUNNERS=8 + if [ "${{ steps.merge_base.outputs.merge_base_strategy }}" == "changedSince" ]; then + RUNNERS=1 + fi + + INDEX_ARRAY=$(seq 0 $(( RUNNERS - 1 )) | jq -s .) + echo "jest_test_matrix=$(jq -nc --argjson index "$INDEX_ARRAY" --argjson total "$RUNNERS" '{index: $index, total: [$total]}')" >> $GITHUB_OUTPUT + typescript: if: needs.files-changed.outputs.frontend_all == 'true' needs: files-changed @@ -178,10 +190,7 @@ jobs: # This helps not having to run multiple jobs because one fails, thus, reducing resource usage # and reducing the risk that one of many runs would turn red again (read: intermittent tests) fail-fast: false - matrix: - # XXX: When updating this, make sure you also update CI_NODE_TOTAL. - - instance: [0, 1, 2, 3, 4, 5, 6, 7] + matrix: ${{ fromJson(needs.files-changed.outputs.jest_test_matrix) }} steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 @@ -198,7 +207,7 @@ jobs: path: | .cache/jest ~/.cache/swc - key: jest-cache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'jest.config.ts') }}-${{ matrix.instance }} + key: jest-cache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'jest.config.ts') }}-${{ matrix.index }} restore-keys: | jest-cache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'jest.config.ts') }}- jest-cache-${{ runner.os }}- @@ -218,13 +227,12 @@ jobs: - name: jest env: + CI_NODE_TOTAL: ${{ matrix.total }} + CI_NODE_INDEX: ${{ matrix.index }} + GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha || github.sha }} GITHUB_PR_REF: ${{ github.event.pull_request.head.ref || github.ref }} - # XXX: CI_NODE_TOTAL must be hardcoded to the length of strategy.matrix.instance. - # Otherwise, if there are other things in the matrix, using strategy.job-total - # wouldn't be correct. - CI_NODE_TOTAL: 8 - CI_NODE_INDEX: ${{ matrix.instance }} + # Disable testing-library from printing out any of of the DOM to # stdout. No one actually looks through this in CI, they're just # going to run it locally.