How to Run Playwright Sharded Across Runners in GitHub Actions
A serial Playwright suite is the long pole in CI; sharding fans it out across runners that each take a slice.
Use --shard=N/M with a matrix over the shard index so each runner executes a disjoint slice of the suite in parallel.
Steps
- Add a matrix over
shard: [1, 2, 3, 4]. - Pass
--shard=${{ matrix.shard }}/4toplaywright test. - Upload the blob report from each shard as an artifact.
- Merge the reports in a follow-up job (see the related guide).
Workflow
.github/workflows/e2e.yml
name: E2E
on: [pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test --shard=${{ matrix.shard }}/4
- uses: actions/upload-artifact@v4
with:
name: blob-report-${{ matrix.shard }}
path: blob-report/Notes
- Set
fail-fast: falseso one slow shard does not cancel the others. - On Latchkey managed runners these parallel shards spin up cheaper and self-heal a dropped shard.
Related guides
How to Merge Coverage from Sharded Jobs in GitHub ActionsCollect per-shard coverage artifacts in GitHub Actions and merge them into one report in a dependent job so a…
How to Run E2E Tests with Playwright and Upload Traces in GitHub ActionsRun Playwright end-to-end tests in GitHub Actions and upload traces and reports as artifacts on failure so yo…