diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 35be9127f8e42..d72432e42a990 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -13,6 +13,8 @@ jobs: module-chunks: ${{ steps.set-module-chunks.outputs.chunks }} api-matrix: ${{ steps.set-api-matrix.outputs.matrix }} api-chunks: ${{ steps.set-api-chunks.outputs.chunks }} + unit-tests-matrix: ${{ steps.set-unit-tests-matrix.outputs.matrix }} + unit-tests-chunks: ${{ steps.set-unit-tests-chunks.outputs.chunks }} steps: - name: Checkout uses: actions/checkout@v3 @@ -36,7 +38,7 @@ jobs: - id: set-module-chunks name: Set Module Chunks working-directory: integration-tests/modules - run: echo "chunks=$(yarn run jest --listTests --json | jq -cM '[_nwise(length / 3 | ceil)]')" >> $GITHUB_OUTPUT + run: echo "chunks=$(yarn run jest --listTests --json | jq -cM '[_nwise(length / 2 | ceil)]')" >> $GITHUB_OUTPUT - id: set-module-matrix name: Set Module Matrix @@ -47,7 +49,7 @@ jobs: - id: set-api-chunks name: Set API Chunks working-directory: integration-tests/api - run: echo "chunks=$(yarn run jest --listTests --json | jq -cM '[_nwise(length / 3 | ceil)]')" >> $GITHUB_OUTPUT + run: echo "chunks=$(yarn run jest --listTests --json | jq -cM '[_nwise(length / 2 | ceil)]')" >> $GITHUB_OUTPUT - id: set-api-matrix name: Set API Matrix @@ -55,9 +57,24 @@ jobs: env: CHUNKS: ${{ steps.set-api-chunks.outputs.chunks }} - unit-tests: + - id: set-unit-tests-chunks + name: Set Unit Tests Chunks + run: echo "chunks=$(yarn workspaces list --json | jq -j '[inputs | .name]' | jq -r | jq -cM '[_nwise(length / 2 | ceil)]')" >> $GITHUB_OUTPUT + + - id: set-unit-tests-matrix + name: Set Unit Tests Matrix + run: echo "matrix=$(echo $CHUNKS | jq -cM 'to_entries | map(.key)')" >> $GITHUB_OUTPUT + env: + CHUNKS: ${{ steps.set-unit-tests-chunks.outputs.chunks }} + + unit-tests-matrix: needs: setup runs-on: ubuntu-latest + name: Shard (${{ matrix.chunk }}) Unit Tests + strategy: + fail-fast: false + matrix: + chunk: ${{ fromJSON(needs.setup.outputs.unit-tests-matrix) }} env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }} @@ -90,7 +107,10 @@ jobs: run: yarn build - name: Run unit tests - run: yarn test + run: yarn test:chunk + env: + CHUNK: ${{ matrix.chunk }} + CHUNKS: ${{ needs.setup.outputs.unit-tests-chunks }} integration-tests-packages: needs: setup @@ -237,6 +257,21 @@ jobs: - run: exit 0 if: ${{ contains(needs.integration-tests-api-matrix.result, 'success') }} + unit-tests: + if: ${{ always() }} + runs-on: ubuntu-latest + needs: unit-tests-matrix + steps: + - run: exit 1 + if: >- + ${{ + contains(needs.unit-tests-matrix.result, 'failure') + || contains(needs.unit-tests-matrix.result, 'cancelled') + || contains(needs.unit-tests-matrix.result, 'skipped') + }} + - run: exit 0 + if: ${{ contains(needs.unit-tests-matrix.result, 'success') }} + integration-tests-plugins: needs: setup runs-on: ubuntu-latest diff --git a/package.json b/package.json index a4c52e8730e42..3b7dce0805b66 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "prettier": "prettier", "jest": "jest", "test": "turbo run test --concurrency=50% --no-daemon", + "test:chunk": "./scripts/run-workspace-unit-tests-in-chunks.sh", "test:integration:packages": "turbo run test:integration --concurrency=50% --no-daemon --filter='./packages/*'", "test:integration:api": "turbo run test:integration:chunk --concurrency=50% --no-daemon --filter=integration-tests-api", "test:integration:plugins": "turbo run test:integration --concurrency=50% --no-daemon --filter=integration-tests-plugins", diff --git a/scripts/run-workspace-unit-tests-in-chunks.sh b/scripts/run-workspace-unit-tests-in-chunks.sh new file mode 100755 index 0000000000000..4b5255611e54f --- /dev/null +++ b/scripts/run-workspace-unit-tests-in-chunks.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Get array of workspaces +# convert NDJSON stream to an array of arrays, divided by chunk size +# get the workspaces of the current CHUNK environment +workspaces=$(echo $CHUNKS | jq -r ".[$CHUNK]") +echo "$workspaces" +# Initialize an empty string for the filters +filters="" + +# Loop through each workspace in the array +for workspace in $(echo "$workspaces" | jq -r '.[]'); do + # Add the workspace name to the filters array as an argument + filters+=" --filter=${workspace}" +done +echo "$filters" +# Run the test in the selected chunk +yarn run test $filters