Skip to content

Commit 60f16fc

Browse files
committed
🤖 ci: optimize Playwright installation with caching and Docker
Addresses slow/flaky CI caused by apt mirror issues during Playwright browser installation. ## Changes ### Storybook tests - Use Docker container (eliminates apt entirely) - Run in mcr.microsoft.com/playwright:v1.56.0-noble container - All browser dependencies are pre-installed in the image - No apt-get calls needed, immune to mirror issues ### E2E tests - Use caching + retry logic - Cache ~/.cache/ms-playwright keyed by Playwright version - On cache hit: only run install-deps (apt for system libs) - On cache miss: run install --with-deps (download + apt) - Add retry logic (3 attempts with 10s delay) for apt flakiness - Install only chromium (sufficient for Electron tests) ## Why not Docker for E2E? E2E tests run Electron which requires xvfb and host display access, making containerization complex. The cache + retry approach handles the apt issue for this case. ## Expected Impact | Job | Before | After | |-----|--------|-------| | Storybook | apt flaky, 3-5 min | No apt, ~1 min | | E2E (cache hit) | apt flaky | apt with retry | | E2E (cache miss) | apt flaky, all browsers | apt with retry, chromium only | _Generated with `mux`_
1 parent 6830b71 commit 60f16fc

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Setup Playwright"
2+
description: "Install Playwright browsers and dependencies with caching"
3+
inputs:
4+
browsers:
5+
description: "Space-separated list of browsers to install (e.g., 'chromium', 'chromium webkit')"
6+
required: false
7+
default: "chromium"
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Get Playwright version
12+
id: playwright-version
13+
shell: bash
14+
run: |
15+
# Extract Playwright version from bun.lock
16+
VERSION=$(grep -A1 '"playwright":' bun.lock | grep -oP '"\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
17+
echo "version=$VERSION" >> $GITHUB_OUTPUT
18+
echo "Playwright version: $VERSION"
19+
20+
- name: Cache Playwright browsers
21+
id: cache-playwright
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.cache/ms-playwright
25+
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}-${{ inputs.browsers }}
26+
restore-keys: |
27+
${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}-
28+
29+
- name: Install Playwright browsers and dependencies
30+
shell: bash
31+
run: |
32+
if [[ "${{ steps.cache-playwright.outputs.cache-hit }}" == "true" ]]; then
33+
echo "Cache hit - installing only system dependencies"
34+
# Retry logic for apt which can be flaky with Azure mirrors
35+
for i in 1 2 3; do
36+
bun x playwright install-deps ${{ inputs.browsers }} && break
37+
echo "Attempt $i failed, retrying in 10s..."
38+
sleep 10
39+
done
40+
else
41+
echo "Cache miss - installing browsers and dependencies"
42+
# install --with-deps downloads browsers AND installs system deps in one command
43+
for i in 1 2 3; do
44+
bun x playwright install --with-deps ${{ inputs.browsers }} && break
45+
echo "Attempt $i failed, retrying in 10s..."
46+
sleep 10
47+
done
48+
fi

.github/workflows/ci.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ jobs:
126126
name: Storybook Interaction Tests
127127
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
128128
if: github.event.inputs.test_filter == ''
129+
# Use Playwright Docker image - has all browser deps pre-installed, no apt needed
130+
container:
131+
image: mcr.microsoft.com/playwright:v1.56.0-noble
132+
options: --user 1001
129133
steps:
130134
- name: Checkout code
131135
uses: actions/checkout@v4
@@ -134,9 +138,6 @@ jobs:
134138

135139
- uses: ./.github/actions/setup-mux
136140

137-
- name: Install Playwright browsers
138-
run: bun x playwright install --with-deps
139-
140141
- name: Build Storybook
141142
run: make storybook-build
142143

@@ -160,16 +161,12 @@ jobs:
160161

161162
- uses: ./.github/actions/setup-mux
162163

163-
- name: Install system dependencies
164+
- name: Install xvfb
164165
run: |
165166
sudo apt-get update
166167
sudo apt-get install -y xvfb
167168
168-
- name: Install Playwright runtime dependencies
169-
run: bun x playwright install-deps
170-
171-
- name: Install Playwright browsers
172-
run: bun x playwright install --with-deps
169+
- uses: ./.github/actions/setup-playwright
173170

174171
- name: Run e2e tests
175172
run: xvfb-run -a make test-e2e

0 commit comments

Comments
 (0)