Skip to content

Commit a1f70c7

Browse files
committed
perf: optimize Playwright CI with sharding and parallel workers
- Split build and test phases to avoid rebuilding 3x (once per browser) - Add test sharding (2 shards per browser) for parallel test execution - Enable parallel workers (50% CPU) in CI instead of sequential - Fix blob report download path for merge-reports job - Add blob-report to gitignore
1 parent 5c3646e commit a1f70c7

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

.github/workflows/build.yml

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,10 @@ jobs:
6565
id: soft-release
6666
run: pnpx pkg-pr-new publish './packages/*' # TODO disabled only for AI branch--compact
6767

68-
playwright:
69-
name: "Playwright Tests - ${{ matrix.browser }}"
68+
playwright-build:
69+
name: "Playwright Build"
7070
runs-on: ubuntu-latest
71-
timeout-minutes: 60
72-
container:
73-
image: mcr.microsoft.com/playwright:v1.51.1-noble
74-
strategy:
75-
fail-fast: false
76-
matrix:
77-
browser: [chromium, firefox, webkit]
71+
timeout-minutes: 30
7872
steps:
7973
- uses: actions/checkout@v4
8074
with:
@@ -95,23 +89,71 @@ jobs:
9589
uses: actions/cache@v4
9690
with:
9791
path: .nx/cache
98-
key: nx-${{ matrix.browser }}-${{ env.NX_BRANCH }}-${{ env.NX_RUN_GROUP }}-${{ github.sha }}
92+
key: nx-playwright-${{ env.NX_BRANCH }}-${{ env.NX_RUN_GROUP }}-${{ github.sha }}
9993
restore-keys: |
100-
nx-${{ matrix.browser }}-${{ env.NX_BRANCH }}-${{ env.NX_RUN_GROUP }}-
101-
nx-${{ matrix.browser }}-${{ env.NX_BRANCH }}-
94+
nx-playwright-${{ env.NX_BRANCH }}-${{ env.NX_RUN_GROUP }}-
95+
nx-playwright-${{ env.NX_BRANCH }}-
10296
nx-
10397
104-
- run: apt-get update && apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config
98+
- run: sudo apt-get update && sudo apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config
10599

106100
- name: Install dependencies
107101
run: pnpm install
108102

109103
- name: Build packages
110104
run: pnpm run build
111105

106+
- name: Cache build artifacts
107+
uses: actions/cache/save@v4
108+
with:
109+
path: |
110+
packages/*/dist
111+
playground/dist
112+
node_modules
113+
packages/*/node_modules
114+
key: playwright-build-${{ github.sha }}
115+
116+
playwright:
117+
name: "Playwright Tests - ${{ matrix.browser }} (${{ matrix.shardIndex }}/${{ matrix.shardTotal }})"
118+
runs-on: ubuntu-latest
119+
needs: playwright-build
120+
timeout-minutes: 30
121+
container:
122+
image: mcr.microsoft.com/playwright:v1.51.1-noble
123+
strategy:
124+
fail-fast: false
125+
matrix:
126+
browser: [chromium, firefox, webkit]
127+
shardIndex: [1, 2]
128+
shardTotal: [2]
129+
steps:
130+
- uses: actions/checkout@v4
131+
with:
132+
fetch-depth: 100
133+
134+
- name: Install pnpm
135+
uses: pnpm/action-setup@v4
136+
137+
- uses: actions/setup-node@v4
138+
with:
139+
cache: "pnpm"
140+
cache-dependency-path: "**/pnpm-lock.yaml"
141+
node-version-file: ".nvmrc"
142+
143+
- name: Restore build artifacts
144+
uses: actions/cache/restore@v4
145+
with:
146+
path: |
147+
packages/*/dist
148+
playground/dist
149+
node_modules
150+
packages/*/node_modules
151+
key: playwright-build-${{ github.sha }}
152+
fail-on-cache-miss: true
153+
112154
- name: Run server and Playwright tests
113155
run: |
114-
HOME=/root PLAYWRIGHT_CONFIG="--project ${{ matrix.browser }}" pnpm run e2e
156+
HOME=/root PLAYWRIGHT_CONFIG="--project ${{ matrix.browser }} --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}" pnpm run e2e
115157
116158
- name: Upload blob report
117159
uses: actions/upload-artifact@v4
@@ -125,7 +167,7 @@ jobs:
125167
uses: actions/upload-artifact@v4
126168
if: ${{ !cancelled() }}
127169
with:
128-
name: playwright-report-${{ matrix.browser }}
170+
name: playwright-report-${{ matrix.browser }}-${{ matrix.shardIndex }}
129171
path: tests/playwright-report/
130172
retention-days: 30
131173

@@ -152,7 +194,7 @@ jobs:
152194
- name: Download blob reports
153195
uses: actions/download-artifact@v4
154196
with:
155-
path: all-blob-reports
197+
path: tests/all-blob-reports
156198
pattern: blob-report-*
157199
merge-multiple: true
158200

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ yarn-error.log*
2929
.vercel
3030
test-results/
3131
playwright-report/
32+
blob-report/
3233
release
3334
/test-results/
3435
/playwright-report/
36+
/blob-report/
3537
/playwright/.cache/
3638
.env
3739
*.pem

tests/playwright.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const config: PlaywrightTestConfig = {
2525
/* Fail the build on CI if you accidentally left test.only in the source code. */
2626
forbidOnly: !!process.env.CI,
2727
retries: 2,
28-
/* Opt out of parallel tests on CI. */
29-
workers: process.env.CI ? 1 : undefined,
28+
/* Run tests in parallel on CI (sharding handles distribution across runners) */
29+
workers: process.env.CI ? "50%" : undefined,
3030
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
3131
reporter: process.env.CI
3232
? [

0 commit comments

Comments
 (0)