diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a29c36743adb..119349c497b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -540,7 +540,7 @@ jobs: pnpm run test job_node_unit_tests: - name: Node (${{ matrix.node }}) Unit Tests + name: Node (${{ matrix.node }}) Unit Tests (${{ matrix.shard }}/2) needs: [job_get_metadata, job_build] timeout-minutes: 10 runs-on: ubuntu-24.04-arm @@ -550,6 +550,7 @@ jobs: fail-fast: false matrix: node: [20.19, 22, 24, 26, '^27.0.0-0'] + shard: [1, 2] steps: - name: Check out base commit (${{ github.event.pull_request.base.sha }}) uses: actions/checkout@v7 @@ -579,12 +580,14 @@ jobs: if: github.event_name == 'pull_request' env: NODE_VERSION: ${{ matrix.node }} + UNIT_TEST_SHARD: ${{ matrix.shard }} - name: Run all tests run: pnpm run test:ci:node if: github.event_name != 'pull_request' env: NODE_VERSION: ${{ matrix.node }} + UNIT_TEST_SHARD: ${{ matrix.shard }} job_browser_playwright_tests: name: diff --git a/scripts/ci-unit-tests.ts b/scripts/ci-unit-tests.ts index f2df019dda33..c8475fe2b506 100644 --- a/scripts/ci-unit-tests.ts +++ b/scripts/ci-unit-tests.ts @@ -4,6 +4,7 @@ import * as path from 'path'; const UNIT_TEST_ENV = process.env.UNIT_TEST_ENV as 'node' | 'browser' | undefined; const RUN_AFFECTED = process.argv.includes('--affected'); +const UNIT_TEST_SHARD = process.env.UNIT_TEST_SHARD; // These packages are tested separately in CI, so no need to run them here const DEFAULT_SKIP_PACKAGES = ['@sentry/bun', '@sentry/deno']; @@ -58,6 +59,21 @@ function runTests(): void { BROWSER_TEST_PACKAGES.forEach(pkg => ignores.add(pkg)); } + if (UNIT_TEST_SHARD) { + if (UNIT_TEST_SHARD !== '1' && UNIT_TEST_SHARD !== '2') { + throw new Error(`Invalid unit-test shard: ${UNIT_TEST_SHARD}`); + } + + packages + .filter(pkg => !ignores.has(pkg)) + .sort() + .forEach((pkg, index) => { + if (index % 2 !== Number(UNIT_TEST_SHARD) - 1) { + ignores.add(pkg); + } + }); + } + if (RUN_AFFECTED) { runAffectedTests(ignores); } else {