Skip to content

Commit 3fa33d4

Browse files
AzgaarCopilot
andcommitted
chore: optimize Playwright test workflow and improve caching strategy
Co-authored-by: Copilot <copilot@github.com>
1 parent 3430c22 commit 3fa33d4

3 files changed

Lines changed: 124 additions & 89 deletions

File tree

.github/workflows/playwright.yml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,45 @@ on:
44
branches: [ master ]
55
jobs:
66
test:
7-
timeout-minutes: 60
7+
timeout-minutes: 30
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v5
11-
- uses: actions/setup-node@v5
12-
with:
13-
node-version: '24'
14-
- name: Install dependencies
15-
run: npm ci
16-
- name: Install Playwright Browsers
17-
run: npx playwright install --with-deps
18-
- name: Run Playwright tests
19-
run: npm run test:e2e
20-
- uses: actions/upload-artifact@v4
21-
if: ${{ !cancelled() }}
22-
with:
23-
name: playwright-report
24-
path: playwright-report/
25-
retention-days: 30
10+
- uses: actions/checkout@v5
11+
- uses: actions/setup-node@v5
12+
with:
13+
node-version: "24"
14+
cache: "npm"
15+
- name: Install dependencies
16+
run: npm ci
17+
- name: Cache Playwright browsers
18+
id: playwright-cache
19+
uses: actions/cache@v4
20+
with:
21+
path: ~/.cache/ms-playwright
22+
key: playwright-chromium-${{ hashFiles('package-lock.json') }}
23+
- name: Install Playwright Browsers
24+
if: steps.playwright-cache.outputs.cache-hit != 'true'
25+
run: npx playwright install --with-deps chromium
26+
- name: Install Playwright system deps
27+
if: steps.playwright-cache.outputs.cache-hit == 'true'
28+
run: npx playwright install-deps chromium
29+
- name: Cache build output
30+
id: dist-cache
31+
uses: actions/cache@v4
32+
with:
33+
path: dist/
34+
key: dist-${{ hashFiles('src/**', 'public/**', 'vite.config.ts',
35+
'tsconfig.json', 'package-lock.json') }}
36+
- name: Build app
37+
if: steps.dist-cache.outputs.cache-hit != 'true'
38+
run: npm run build
39+
- name: Run Playwright tests
40+
run: npm run test:e2e
41+
env:
42+
SKIP_BUILD: "1"
43+
- uses: actions/upload-artifact@v4
44+
if: ${{ !cancelled() }}
45+
with:
46+
name: playwright-report
47+
path: playwright-report/
48+
retention-days: 30

playwright.config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { defineConfig, devices } from '@playwright/test'
22

33
const isCI = !!process.env.CI
4+
const skipBuild = !!process.env.SKIP_BUILD
45

56
export default defineConfig({
67
testDir: './tests/e2e',
78
fullyParallel: true,
89
forbidOnly: isCI,
9-
retries: isCI ? 2 : 0,
10-
workers: isCI ? 1 : undefined,
10+
retries: 0,
11+
workers: isCI ? 2 : undefined,
1112
reporter: 'html',
1213
// Use OS-independent snapshot names (HTML content is the same across platforms)
1314
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}',
@@ -24,9 +25,9 @@ export default defineConfig({
2425
},
2526
],
2627
webServer: {
27-
// In CI: build and preview for production-like testing
28+
// In CI: build (done as a separate cached step) and preview for production-like testing
2829
// In dev: use vite dev server (faster, no rebuild needed)
29-
command: isCI ? 'npm run build && npm run preview' : 'npm run dev',
30+
command: isCI ? (skipBuild ? 'npm run preview' : 'npm run build && npm run preview') : 'npm run dev',
3031
url: isCI ? 'http://localhost:4173' : 'http://localhost:5173',
3132
reuseExistingServer: !isCI,
3233
timeout: 120000,

0 commit comments

Comments
 (0)