Skip to content

fix: improve Playwright browser cache in CI#60

Merged
Quafadas merged 2 commits into
mainfrom
copilot/improve-playwright-caching
Mar 30, 2026
Merged

fix: improve Playwright browser cache in CI#60
Quafadas merged 2 commits into
mainfrom
copilot/improve-playwright-caching

Conversation

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

The Playwright cache step had three issues: pinned to @main (unstable), used a hardcoded runner path, and set restore-keys identical to key (making it a no-op fallback).

Changes

  • actions/cache@mainactions/cache@v4 — stable, versioned pin
  • Cache path/home/runner/.cache/ms-playwright~/.cache/ms-playwright
  • restore-keys — prefix-only fallback so a Playwright version bump still yields a partial cache hit instead of a cold start
- name: Cache Playwright dependencies
  uses: actions/cache@v4
  with:
    path: ~/.cache/ms-playwright
    key: playwright-${{ runner.os }}-${{ hashFiles('playwrightVersion.mill') }}
    restore-keys: |
      playwright-${{ runner.os }}-
Original prompt

Create a pull request to improve Playwright caching in the GitHub Actions workflow.

Repository: Quafadas/live-server-scala-cli-js
Target file: .github/workflows/ci.yml (on branch main)

Changes requested:

  1. Update the Playwright cache step to use a stable actions/cache version tag (v4) instead of @main.
  2. Change the cache path from a hard-coded /home/runner/.cache/ms-playwright to ~/.cache/ms-playwright.
  3. Fix restore-keys so it provides a useful fallback. Current restore-keys is identical to the key. Update it to restore by prefix, e.g.:
    • key: playwright-${{ runner.os }}-${{ hashFiles('playwrightVersion.mill') }}
    • restore-keys: |
      playwright-${{ runner.os }}-
  4. Keep the key format as-is (still based on hashFiles('playwrightVersion.mill')) unless the implementation requires small adjustments for correctness.

Acceptance criteria:

  • Workflow YAML remains valid.
  • Cache step correctly restores an older Playwright cache when the exact key is missing.
  • No other functional changes to the workflow besides the caching improvements.

Reference URL: https://github.com/Quafadas/live-server-scala-cli-js/blob/main/.github/workflows/ci.yml

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: is playwright here correctly cached?

Assistant: No — it’s partially right, but it’s not robust, and the cache key logic is a bit off.

What you’re caching

You cache:

path: /home/runner/.cache/ms-playwright

That is the correct directory for Playwright browser downloads on Linux runners (the “ms-playwright” browser cache). So the path choice is good.

What’s wrong / suboptimal

1) restore-keys is ineffective as written

You have:

key: playwright-${{ runner.os }}-${{ hashFiles('playwrightVersion.mill') }}
restore-keys: |
  playwright-${{ runner.os }}-${{ hashFiles('playwrightVersion.mill') }}

That restore-keys entry is identical to the key, so it won’t ever fall back to “closest match”. If the exact key doesn’t exist, it restores nothing.

Usually you want a prefix fallback, e.g. playwright-${{ runner.os }}- so that if the version file changes, you can still restore an older browser cache.

2) Cache key depends on playwrightVersion.mill existing + actually changing

If playwrightVersion.mill:

  • doesn’t exist,
  • isn’t what actually controls the Playwright version used by just setupPlaywright,
  • or isn’t updated when Playwright changes,

…then your cache key won’t track the real browser revision, and you can end up restoring a cache that doesn’t match what Playwright expects (which can cause Playwright to re-download anyway).

3) Your install step may not use that cache unless it downloads to that path

Whether this cache works in practice depends on what just setupPlaywright does:

  • If it runs something like playwright install (Node) or equivalent that downloads browsers into ~/.cache/ms-playwright, then the cache will help.
  • If it sets PLAYWRIGHT_BROWSERS_PATH to some other directory, then you’re caching the wrong path.

Recommended fix (minimal)

- name: Cache Playwright browsers
  uses: actions/cache@v4
  with:
    path: ~/.cache/ms-playwright
    key: playwright-${{ runner.os }}-${{ hashFiles('playwrightVersion.mill') }}
    restore-keys: |
      playwright-${{ runner.os }}-

Notes:

  • ~/.cache/ms-playwright is cleaner than hardcoding /home/runner/....
  • Use actions/cache@v4 (instead of @main) for stability.

If you want me to be definitive

Paste the contents of:

  • playwrightVersion.mill
  • your Justfile target setupPlaywright (or wherever it’s defined)

…and I can tell you if the cached path and the key truly match the Playwright version/download location you’re using.

User: Can you open a PR for this please?

Assistant: I’ve queued up the pull request creation, and I’m waiting on your confirmation in the approval dialog to proceed with opening it.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Improve Playwright caching in GitHub Actions workflow fix: improve Playwright browser cache in CI Mar 30, 2026
Copilot AI requested a review from Quafadas March 30, 2026 13:44
@Quafadas

Copy link
Copy Markdown
Owner

@copilot

Here's the just command to setup playwright.

setupPlaywright:
cs launch com.microsoft.playwright:playwright:1.51.0 -M "com.microsoft.playwright.CLI" -- install --with-deps

Does that change anything?

@Quafadas Quafadas marked this pull request as ready for review March 30, 2026 13:58

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Here's the just command to setup playwright.
...

No changes needed. playwright install (invoked via the Playwright CLI) downloads browsers to ~/.cache/ms-playwright by default on Linux, so the cache path is correct.

The version in the just command (1.51.0) matches playwrightVersion.mill (val pwV = "1.51.0"), so the cache key accurately tracks the actual browser version being installed. The setup is fine as-is.

@Quafadas Quafadas merged commit e91af97 into main Mar 30, 2026
5 checks passed
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.

2 participants