From 5688687011b947dd4c85636c136a9e6d5ab27a9c Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 18 May 2026 15:12:26 +0800 Subject: [PATCH] perf(ci): cache Playwright browsers and apt packages in PR checks (#4215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci(e2e): cache Playwright browsers and apt packages - cache `~/.cache/ms-playwright` keyed on the lockfile; on a hit only the OS deps are installed, skipping the browser download - cache apt archives in test_web_app, matching the rust/tauri jobs Co-Authored-By: Claude Opus 4.7 (1M context) * ci: enable Turbopack persistent cache and key it for cross-PR reuse Enable `experimental.turbopackFileSystemCacheForBuild` so `next build` persists a real Turbopack cache (~640 MB at `.next/cache/turbopack`), instead of the ~340 KB of metadata the previous `.next/cache` cache held. Dev caching is already on by default in Next 16.1+. Redesign the cache keys so they actually pay off: - drop `${{ github.sha }}` from the key — it made every commit a unique entry that no other PR could exact-hit. The key is now `turbo----`, deterministic across branches, so every PR restores the same entry (in practice the one `main` last saved — the only cache sibling PRs can all see). - `build_web_app` (`next build`) caches `.next/cache`; `build_tauri_app` (`next dev`) caches `.next/dev/cache` — `next dev`'s Turbopack cache lives in a different directory. - drop the Next.js cache step from `test_web_app`; it runs no build. Co-Authored-By: Claude Opus 4.7 (1M context) --------- Co-authored-by: Claude Opus 4.7 (1M context) --- .github/workflows/pull-request.yml | 65 +++++++++++++++++++++--------- apps/readest-app/next.config.mjs | 7 ++++ 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f87bf136..610426e4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -58,14 +58,17 @@ jobs: node-version: 24 cache: pnpm - - name: cache Next.js build + # Turbopack persists its build cache here (turbopackFileSystemCacheForBuild). + # The key is deterministic (no commit SHA) so every PR restores the same + # entry — in practice the one `main` last saved, which is the only cache + # sibling PRs can all see. + - name: cache Turbopack build cache uses: actions/cache@v5 with: path: apps/readest-app/.next/cache - key: nextjs-web-${{ github.sha }}-${{ hashFiles('pnpm-lock.yaml') }} + key: turbo-build-web-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | - nextjs-web-${{ github.sha }}- - nextjs-web- + turbo-build-web-${{ runner.os }}- - name: install Dependencies working-directory: apps/readest-app @@ -89,9 +92,21 @@ jobs: run: | pnpm build-web && pnpm check:all + - name: cache playwright browsers + id: playwright-cache + uses: actions/cache@v5 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} + - name: install playwright browsers working-directory: apps/readest-app - run: npx playwright install --with-deps chromium + run: | + if [ "${{ steps.playwright-cache.outputs.cache-hit }}" = 'true' ]; then + npx playwright install-deps chromium + else + npx playwright install --with-deps chromium + fi - name: run web e2e tests id: web_e2e @@ -122,20 +137,17 @@ jobs: node-version: 24 cache: pnpm - - name: cache Next.js build - uses: actions/cache@v5 - with: - path: apps/readest-app/.next/cache - key: nextjs-test-${{ github.sha }}-${{ hashFiles('pnpm-lock.yaml') }} - restore-keys: | - nextjs-test-${{ github.sha }}- - nextjs-test- - - name: install Dependencies working-directory: apps/readest-app run: | pnpm install && pnpm setup-vendors + - name: cache apt packages + uses: actions/cache@v5 + with: + path: /var/cache/apt/archives + key: apt-test-web-${{ runner.os }} + - name: install LuaJIT + busted (for koplugin tests) run: | sudo apt-get update @@ -149,9 +161,21 @@ jobs: sudo luarocks --lua-version=5.1 install busted sudo luarocks --lua-version=5.1 install lsqlite3complete + - name: cache playwright browsers + id: playwright-cache + uses: actions/cache@v5 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} + - name: install playwright browsers working-directory: apps/readest-app - run: npx playwright install --with-deps chromium + run: | + if [ "${{ steps.playwright-cache.outputs.cache-hit }}" = 'true' ]; then + npx playwright install-deps chromium + else + npx playwright install --with-deps chromium + fi - name: run web tests working-directory: apps/readest-app @@ -180,14 +204,15 @@ jobs: node-version: 24 cache: pnpm - - name: cache Next.js build + # The tauri tests run `next dev`, whose Turbopack cache lives in + # `.next/dev/cache` (a different path from the `next build` cache). + - name: cache Turbopack dev cache uses: actions/cache@v5 with: - path: apps/readest-app/.next/cache - key: nextjs-tauri-${{ github.sha }}-${{ hashFiles('pnpm-lock.yaml') }} + path: apps/readest-app/.next/dev/cache + key: turbo-dev-tauri-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} restore-keys: | - nextjs-tauri-${{ github.sha }}- - nextjs-tauri- + turbo-dev-tauri-${{ runner.os }}- - name: install Dependencies working-directory: apps/readest-app diff --git a/apps/readest-app/next.config.mjs b/apps/readest-app/next.config.mjs index eda4b3c7..cad5ea63 100644 --- a/apps/readest-app/next.config.mjs +++ b/apps/readest-app/next.config.mjs @@ -27,6 +27,13 @@ const nextConfig = { unoptimized: true, }, devIndicators: false, + experimental: { + // Persist Turbopack's compilation cache to `.next/` so CI can restore it + // between runs. Dev caching is on by default since Next 16.1; build + // caching is opt-in (beta). + turbopackFileSystemCacheForDev: true, + turbopackFileSystemCacheForBuild: true, + }, // Configure assetPrefix or else the server won't properly resolve your assets. assetPrefix: '', reactStrictMode: true,