Skip to content

Cache Playwright browsers in CI to prevent download hangs#70

Merged
fynyky merged 1 commit into
masterfrom
claude/fix-playwright-ci-cache
May 29, 2026
Merged

Cache Playwright browsers in CI to prevent download hangs#70
fynyky merged 1 commit into
masterfrom
claude/fix-playwright-ci-cache

Conversation

@fynyky
Copy link
Copy Markdown
Owner

@fynyky fynyky commented May 29, 2026

Summary

  • Adds actions/cache@v4 for ~/.cache/ms-playwright in both test.yml and publish.yml
  • Cache key is based on package-lock.json hash, so it busts when Playwright version changes
  • Placed after npm ci and before npm test, which is where pretest runs npx playwright install --with-deps

Test plan

  • CI passes on this PR
  • On a second run (cache hit), verify the workflow completes faster with no browser download

🤖 Generated with Claude Code

The pretest script downloads all three browsers (~500MB total) on every
run with no caching. Downloads were hanging after Chrome completed,
blocking the test and publish workflows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude Bot commented May 29, 2026

Claude finished @fynyky's task in 1m 13s —— View job


Claude PR Review

The change is small, well-scoped, and correctly placed — the cache step sits between npm ci and npm test, so it restores before pretest invokes npx playwright install. A few suggestions, none of them blocking.


1. Cache key should include runner.os (correctness, low priority)

Playwright browsers are OS/arch-specific binaries. Today both workflows run on ubuntu-latest, so a collision can't happen — but the key as written is a footgun for anyone who later adds a windows-latest or macos-latest matrix entry: jobs would share a key and restore the wrong binaries.

key: playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}

.github/workflows/test.yml:20 and .github/workflows/publish.yml:24.

Fix this →

2. Consider restore-keys for partial matches (optimization)

The current key busts the cache on any package-lock.json change — even unrelated bumps like chai or parcel. Adding a restore-keys fallback would still restore the most recent Playwright cache; npx playwright install then validates installed browsers and only downloads what's missing (or nothing, if Playwright itself didn't change).

- uses: actions/cache@v4
  with:
    path: ~/.cache/ms-playwright
    key: playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
    restore-keys: |
      playwright-${{ runner.os }}-

This is the bigger win in practice — the test suite uses chromium, firefox, and webkit (per test/web-test-runner.config.mjs), so the download cost on a cache miss is meaningful.

3. --with-deps still runs apt-get on cache hits (informational, not a defect)

The pretest script runs npx playwright install --with-deps. The --with-deps flag still triggers an apt-get install for system libraries on every run, regardless of cache state — those packages don't persist between runner VMs. So the cache eliminates the browser download (the part that was hanging), but not the apt step. That's fine and expected; just worth knowing the cache hit isn't a no-op.

4. publish.yml is missing a trailing newline (nit)

The diff shows \ No newline at end of file on .github/workflows/publish.yml. Minor, but worth tidying since test.yml has one.

5. Lockfile-pinned Playwright is the right anchor

Keying on package-lock.json rather than just package.json is the correct call here — package.json pins playwright to 1.59.1 exactly, but package-lock.json is the actual source of truth for what npm ci installs (including transitive resolution), so this won't drift.


Summary

LGTM with the suggestion to add runner.os to the key (cheap insurance) and optionally restore-keys (better cache hit rate across unrelated lockfile changes). The placement, scope, and cache path are all correct.

  • Read the changed workflow files
  • Inspect repo for Playwright config / pretest hook
  • Analyze cache key correctness and placement
  • Post review feedback
    · Branch

@fynyky fynyky merged commit 25976d5 into master May 29, 2026
1 of 2 checks passed
@fynyky fynyky deleted the claude/fix-playwright-ci-cache branch May 29, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant