From c58ed9dbe1c46388d0f18085af6eb511f0483810 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 3 Apr 2024 23:11:14 +0200 Subject: [PATCH] Tests: Shard JS unit tests (#60045) Split out JS date unit tests Shard main JS unit tests into 4 shards. By sharding the tests, they can run in parallel on different runners. This allows the job to complete in less time. Testing suggests the time is reduced by around 50% from 4m to 2m. Co-authored-by: sirreal Co-authored-by: desrosj --- .github/workflows/unit-test.yml | 59 +++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5853f8fcc7a510..12b6eb9b0bf165 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,16 +21,18 @@ concurrency: jobs: unit-js: - name: JavaScript (Node.js ${{ matrix.node }}) + name: JavaScript (Node.js ${{ matrix.node }}) ${{ matrix.shard }} runs-on: ubuntu-latest if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} strategy: fail-fast: false matrix: node: ['20', '21'] + shard: ['1/4', '2/4', '3/4', '4/4'] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - name: Checkout repository + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 with: show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} @@ -39,20 +41,55 @@ jobs: with: node-version: ${{ matrix.node }} - - name: Get number of CPU cores + - name: Determine the number of CPU cores uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0 id: cpu-cores - - name: npm build + - name: Run build scripts # It's not necessary to run the full build, since Jest can interpret # source files with `babel-jest`. Some packages have their own custom # build tasks, however. These must be run. run: npx lerna run build - name: Running the tests - run: npm run test:unit -- --ci --maxWorkers=${{ steps.cpu-cores.outputs.count }} --cacheDirectory="$HOME/.jest-cache" + run: | + npm run test:unit -- \ + --ci \ + --maxWorkers="${{ steps.cpu-cores.outputs.count }}" \ + --shard="${{ matrix.shard }}" \ + --cacheDirectory="$HOME/.jest-cache" + + unit-js-date: + name: JavaScript Date Tests (Node.js ${{ matrix.node }}) + runs-on: ubuntu-latest + if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} + strategy: + fail-fast: false + matrix: + node: ['20', '21'] + + steps: + - name: Checkout repository + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Setup Node.js and install dependencies + uses: ./.github/setup-node + with: + node-version: ${{ matrix.node }} + + - name: Determine the number of CPU cores + uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0 + id: cpu-cores - - name: Running the date tests + - name: Run build scripts + # It's not necessary to run the full build, since Jest can interpret + # source files with `babel-jest`. Some packages have their own custom + # build tasks, however. These must be run. + run: npx lerna run build + + - name: Run the date tests run: npm run test:unit:date -- --ci --maxWorkers=${{ steps.cpu-cores.outputs.count }} --cacheDirectory="$HOME/.jest-cache" compute-previous-wordpress-version: @@ -134,7 +171,8 @@ jobs: WP_ENV_CORE: ${{ matrix.wordpress == '' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wordpress ) }} steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - name: Checkout repository + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 with: show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} @@ -314,18 +352,19 @@ jobs: if: ${{ github.repository == 'WordPress/gutenberg' || github.event_name == 'pull_request' }} steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - name: Checkout repository + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 with: show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - name: Get number of CPU cores + - name: Determine the number of CPU cores uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2.0.0 id: cpu-cores - name: Setup Node.js and install dependencies uses: ./.github/setup-node - - name: Npm build + - name: Run build scripts # It's not necessary to run the full build, since Jest can interpret # source files with `babel-jest`. Some packages have their own custom # build tasks, however. These must be run.