You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/10/24 12:16:20 UTC

(magpie-site) branch main updated: Speed up the Playwright install on slow runners (#250)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/magpie-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 2d29c63  Speed up the Playwright install on slow runners (#250)
2d29c63 is described below

commit 2d29c635c6e3cb105b48b06ae04b60748144e24c
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sat Oct 24 14:16:13 2026 +0200

    Speed up the Playwright install on slow runners (#250)
    
    On a slow runner, shard 10 of #248 spent ten of its fifteen minutes before
    its first test: nearly three installing the cached packages and almost two
    downloading browsers. dpkg now skips syncing each file (force-unsafe-io; the
    runner is thrown away after the job), only the headless shell the suites run
    is installed (--only-shell), and the browser is cached in the workspace,
    keyed by the Playwright version, alongside the apt cache.
    
    Generated-by: Claude Opus 5
---
 .github/actions/playwright-chromium/action.yml | 44 ++++++++++++++++++++++----
 .github/workflows/browser-tests.yml            |  3 ++
 .github/workflows/playwright-cache.yml         |  2 ++
 .gitignore                                     |  3 +-
 4 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/.github/actions/playwright-chromium/action.yml b/.github/actions/playwright-chromium/action.yml
index ffca4fe..0bd767c 100644
--- a/.github/actions/playwright-chromium/action.yml
+++ b/.github/actions/playwright-chromium/action.yml
@@ -16,13 +16,14 @@
 # under the License.
 
 ---
-# Installs Chromium and its system packages for Playwright, after `npm ci`.
-# The browser suites only restore the apt cache; playwright-cache.yml saves it.
+# Installs Playwright's headless Chromium and its system packages, after
+# `npm ci`. The browser suites only restore the caches; playwright-cache.yml
+# saves them.
 name: "Playwright Chromium"
-description: "Install Playwright's Chromium with its apt packages kept in the Actions cache"
+description: "Install Playwright's headless Chromium with its apt packages and browser kept in the Actions cache"
 inputs:
   save:
-    description: "Save the apt cache after the install when the key was not an exact hit"
+    description: "Save the caches after the install when their key was not an exact hit"
     default: "false"
 runs:
   using: composite
@@ -46,8 +47,19 @@ runs:
     # Inside the workspace is the same relative place on both; actions/cache
     # refuses a path with `..`, so it cannot sit beside it. The path is also
     # part of the cache's version, so it is written the same way, as a
-    # relative literal, in both steps below. .gitignore lists the directory.
-    - name: Keep apt's downloads for the cache
+    # relative literal, in each cache step below. .gitignore lists the
+    # directories.
+    #
+    # On a slow runner, unpacking and setting up these packages took almost
+    # three minutes, against seconds elsewhere. dpkg syncs every file it
+    # writes to disk; force-unsafe-io skips that, and the runner is thrown
+    # away after the job, so nothing needs the files to survive a crash.
+    #
+    # The browser is cached the same way, inside the workspace, keyed by the
+    # Playwright version, which pins the browser build. The suites must find it
+    # there too, so the calling job sets PLAYWRIGHT_BROWSERS_PATH, relative so
+    # it resolves against the workspace on both; this step checks it.
+    - name: Keep apt's downloads and the browser for the cache
       id: apt-cache
       shell: bash
       run: |
@@ -56,22 +68,40 @@ runs:
         mkdir -p "${cache}/partial"
         ${sudo} rm -f /etc/apt/apt.conf.d/docker-clean
         echo "Dir::Cache::Archives \"${cache}\";" | ${sudo} tee /etc/apt/apt.conf.d/99playwright-cache
+        if [ "${PLAYWRIGHT_BROWSERS_PATH:-}" != .playwright-browsers ]; then
+          echo "::error::set PLAYWRIGHT_BROWSERS_PATH: .playwright-browsers in the job's env, so the suites find the cached browser"
+          exit 1
+        fi
+        echo force-unsafe-io | ${sudo} tee /etc/dpkg/dpkg.cfg.d/99playwright-unsafe-io
         . /etc/os-release
         echo "os=${ID}-${VERSION_ID}" >> "${GITHUB_OUTPUT}"
         echo "week=$(date -u +%G-W%V)" >> "${GITHUB_OUTPUT}"
+        echo "playwright=$(node -p 'require("@playwright/test/package.json").version')" >> "${GITHUB_OUTPUT}"
     - id: restore
       uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
       with:
         path: .apt-cache/*.deb
         key: playwright-apt-${{ steps.apt-cache.outputs.os }}-${{ steps.apt-cache.outputs.week }}
         restore-keys: playwright-apt-${{ steps.apt-cache.outputs.os }}-
+    - id: restore-browser
+      uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+      with:
+        path: .playwright-browsers
+        key: playwright-browser-${{ steps.apt-cache.outputs.os }}-${{ steps.apt-cache.outputs.playwright }}
+    # The suites run headless, which uses the headless shell: the full Chrome
+    # Playwright also installs by default is never started.
     - shell: bash
       run: |
         sudo=$(command -v sudo || true)
-        npx playwright install --with-deps chromium
+        npx playwright install --with-deps --only-shell chromium
         ${sudo} apt-get autoclean
     - if: inputs.save == 'true' && steps.restore.outputs.cache-hit != 'true'
       uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
       with:
         path: .apt-cache/*.deb
         key: ${{ steps.restore.outputs.cache-primary-key }}
+    - if: inputs.save == 'true' && steps.restore-browser.outputs.cache-hit != 'true'
+      uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+      with:
+        path: .playwright-browsers
+        key: ${{ steps.restore-browser.outputs.cache-primary-key }}
diff --git a/.github/workflows/browser-tests.yml b/.github/workflows/browser-tests.yml
index 853085e..1c0b908 100644
--- a/.github/workflows/browser-tests.yml
+++ b/.github/workflows/browser-tests.yml
@@ -33,6 +33,9 @@ jobs:
   browser:
     runs-on: ubuntu-slim
     timeout-minutes: 15
+    env:
+      # Where the playwright-chromium action caches the browser.
+      PLAYWRIGHT_BROWSERS_PATH: .playwright-browsers
     strategy:
       fail-fast: false
       matrix:
diff --git a/.github/workflows/playwright-cache.yml b/.github/workflows/playwright-cache.yml
index ca60917..7a1d3dd 100644
--- a/.github/workflows/playwright-cache.yml
+++ b/.github/workflows/playwright-cache.yml
@@ -62,6 +62,8 @@ jobs:
     timeout-minutes: 45
     env:
       DEBIAN_FRONTEND: noninteractive
+      # Where the playwright-chromium action caches the browser.
+      PLAYWRIGHT_BROWSERS_PATH: .playwright-browsers
     steps:
       - name: Check the container is ubuntu-slim's release
         env:
diff --git a/.gitignore b/.gitignore
index 192235f..38b13cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,8 +14,9 @@ src/data/tools.json
 # dependencies
 node_modules/
 
-# Playwright's apt downloads in CI (.github/actions/playwright-chromium)
+# Playwright's apt downloads and browser in CI (.github/actions/playwright-chromium)
 .apt-cache/
+.playwright-browsers/
 
 # logs
 npm-debug.log*