Skip to content

Commit 3a099e7

Browse files
committed
ci: enable test sharding for faster CI
Changes: - Enable sharded unit tests (3 shards × 3 OS = 9 jobs) - Reduce test time from 48s → ~16-20s per shard - Disable tests in main ci job (run in sharded job instead) - Reduce max-parallel from 8 to 4 (respects macOS concurrency limits) - Reduce timeout from 20 to 10 minutes (shards run faster) - Add needs: ci to ensure lint/type checks pass first Benefits: - Faster wall-clock time (~16-20s vs 48s) - Better parallelization across GitHub runners - Respects GitHub Actions macOS concurrency limits (max 5 concurrent)
1 parent 53071f6 commit 3a099e7

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,41 @@ jobs:
4343
test-setup-script: 'pnpm --filter @socketsecurity/cli run build'
4444
lint-script: 'pnpm --filter @socketsecurity/cli run check'
4545
type-check-script: 'pnpm --filter @socketsecurity/cli run type'
46-
test-script: ${{ inputs.skip-tests && 'echo "Tests skipped"' || 'pnpm --filter @socketsecurity/cli run test:unit' }}
46+
test-script: 'echo "Tests run in sharded job below"'
4747
node-versions: ${{ inputs.node-versions || '["24.10.0"]' }}
4848
os-versions: '["ubuntu-latest", "macos-latest", "windows-latest"]'
4949
fail-fast: false
50-
# Increase parallelization for socket-cli's longer test suite (~48s).
51-
# Default is 4, we increase to 8 for better performance.
52-
max-parallel: 8
53-
# Increase timeout for slower subprocess-heavy tests.
54-
test-timeout-minutes: 20
50+
# Reduced from 8 to 4 with sharding enabled.
51+
max-parallel: 4
52+
# Reduced timeout with sharding (each shard runs faster).
53+
test-timeout-minutes: 15
5554

56-
# Sharded unit tests (optional, enable for faster CI).
57-
# To enable: uncomment this job and set `run-test: false` in the ci job above.
58-
# test-sharded:
59-
# name: Unit Tests (Sharded ${{ matrix.shard }}/3)
60-
# runs-on: ${{ matrix.os }}
61-
# timeout-minutes: 15
62-
# strategy:
63-
# fail-fast: false
64-
# matrix:
65-
# node-version: ${{ fromJSON(inputs.node-versions || '["24.10.0"]') }}
66-
# os: [ubuntu-latest, macos-latest, windows-latest]
67-
# shard: [1, 2, 3]
68-
# steps:
69-
# - uses: SocketDev/socket-registry/.github/actions/setup-and-install@51be85d39d3b4a42dd9d4712948b9d30a2e04794
70-
# with:
71-
# node-version: ${{ matrix.node-version }}
72-
#
73-
# - name: Build CLI
74-
# working-directory: packages/cli
75-
# run: pnpm run build
76-
#
77-
# - name: Run unit tests (shard ${{ matrix.shard }})
78-
# working-directory: packages/cli
79-
# run: pnpm test:unit --shard=${{ matrix.shard }}/3
55+
# Sharded unit tests for faster CI.
56+
# Splits 2,819 tests across 3 shards (~16s per shard vs 48s monolithic).
57+
test-sharded:
58+
name: Unit Tests (Shard ${{ matrix.shard }}/3)
59+
needs: ci
60+
runs-on: ${{ matrix.os }}
61+
timeout-minutes: 10
62+
strategy:
63+
fail-fast: false
64+
max-parallel: 4
65+
matrix:
66+
node-version: ${{ fromJSON(inputs.node-versions || '["24.10.0"]') }}
67+
os: [ubuntu-latest, macos-latest, windows-latest]
68+
shard: [1, 2, 3]
69+
steps:
70+
- uses: SocketDev/socket-registry/.github/actions/setup-and-install@51be85d39d3b4a42dd9d4712948b9d30a2e04794
71+
with:
72+
node-version: ${{ matrix.node-version }}
73+
74+
- name: Build CLI
75+
working-directory: packages/cli
76+
run: pnpm run build
77+
78+
- name: Run unit tests (shard ${{ matrix.shard }})
79+
working-directory: packages/cli
80+
run: pnpm test:unit --shard=${{ matrix.shard }}/3
8081

8182
e2e:
8283
name: E2E Tests

0 commit comments

Comments
 (0)