Skip to content

Commit 092e889

Browse files
CopilotDevSecNinja
andauthored
Reduce repeated Playwright setup time in E2E CI (#74)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Jean-Paul van Ravensberg <14926452+DevSecNinja@users.noreply.github.com>
1 parent bd07a36 commit 092e889

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
name: E2E
33

4-
# Runs the Playwright end-to-end + mobile/responsive suite across Chromium,
4+
# Runs the Playwright end-to-end + mobile/responsive suite. To keep PR feedback
5+
# fast, pull requests run only the Chromium engine (desktop + emulated mobile);
6+
# pushes to main and manual runs exercise the full matrix across Chromium,
57
# Firefox and WebKit (desktop) plus emulated mobile devices. Unit/component
68
# tests (Vitest) run in the Pages workflow; this workflow focuses on real
79
# browser flows. See playwright.config.js for projects and the dev web server.
@@ -49,20 +51,66 @@ jobs:
4951
- name: Install dependencies
5052
run: npm ci
5153

54+
- name: Determine browser scope
55+
id: scope
56+
# PRs validate against the Chromium engine only (desktop + mobile-chrome)
57+
# for fast feedback; main / manual runs cover the full browser matrix.
58+
run: |-
59+
if [ "${{ github.event_name }}" = "pull_request" ]; then
60+
{
61+
echo "browsers=chromium"
62+
echo "projects=--project=chromium --project=mobile-chrome"
63+
echo "label=chromium"
64+
} >> "$GITHUB_OUTPUT"
65+
else
66+
{
67+
echo "browsers=chromium firefox webkit"
68+
echo "projects="
69+
echo "label=all"
70+
} >> "$GITHUB_OUTPUT"
71+
fi
72+
73+
- name: Resolve Playwright version
74+
id: playwright-version
75+
# Key the cache on the resolved Playwright version (stable across
76+
# lockfile churn) rather than hashFiles(package-lock.json).
77+
run: |-
78+
version=$(node -p "require('./package-lock.json').packages['node_modules/@playwright/test'].version")
79+
echo "version=$version" >> "$GITHUB_OUTPUT"
80+
5281
- name: Cache Playwright browsers
5382
id: playwright-cache
5483
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
5584
with:
5685
path: ~/.cache/ms-playwright
57-
key: playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
58-
restore-keys: |-
59-
playwright-${{ runner.os }}-
86+
key: >-
87+
playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}-${{
88+
steps.scope.outputs.label }}
6089
6190
- name: Install Playwright browsers
62-
run: npx playwright install --with-deps
91+
if: steps.playwright-cache.outputs.cache-hit != 'true'
92+
env:
93+
BROWSERS: ${{ steps.scope.outputs.browsers }}
94+
run: |-
95+
# shellcheck disable=SC2086 # intentional word splitting into args
96+
npx playwright install $BROWSERS --with-deps
97+
98+
- name: Install Playwright system dependencies
99+
# Browser binaries are cached, but apt system libraries are not persisted
100+
# across ephemeral runners, so refresh them on a cache hit.
101+
if: steps.playwright-cache.outputs.cache-hit == 'true'
102+
env:
103+
BROWSERS: ${{ steps.scope.outputs.browsers }}
104+
run: |-
105+
# shellcheck disable=SC2086 # intentional word splitting into args
106+
npx playwright install-deps $BROWSERS
63107
64108
- name: Run Playwright tests
65-
run: npm run test:e2e
109+
env:
110+
PROJECTS: ${{ steps.scope.outputs.projects }}
111+
run: |-
112+
# shellcheck disable=SC2086 # intentional word splitting into args
113+
npm run test:e2e -- $PROJECTS
66114
67115
- name: Upload Playwright report
68116
if: ${{ !cancelled() }}

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
fullyParallel: true,
1313
forbidOnly: !!process.env.CI,
1414
retries: process.env.CI ? 2 : 0,
15-
workers: process.env.CI ? 1 : undefined,
15+
workers: process.env.CI ? 2 : undefined,
1616
reporter: process.env.CI
1717
? [['html', { open: 'never' }], ['github'], ['list']]
1818
: [['html', { open: 'never' }], ['list']],

0 commit comments

Comments
 (0)