From 064d5a67b24913ad9fa3f805d06e977198c1466c Mon Sep 17 00:00:00 2001 From: snomiao Date: Tue, 7 Oct 2025 00:25:26 +0000 Subject: [PATCH] refactor: improve .cache directory caching strategy Changes: - Move cache restore to setup-frontend action BEFORE build operations - Remove duplicate cache step from setup-playwright action - Use cache/restore instead of cache to avoid auto-save behavior - Rename cache key from 'playwright-setup-cache' to 'tool-cache' for clarity - Include source file hashes in cache key for proper invalidation Benefits: - Cache is now restored before tools run, allowing them to use cached data - Eliminates duplicate caching of ./.cache directory - Cache properly invalidates when source files or configs change - Follows GitHub Actions best practice of restore before, save after pattern - The workspace cache in tests-ci.yaml handles saving the complete state Note: The .cache directory contains outputs from ESLint, Prettier, Stylelint, Knip, and TypeScript incremental builds. These should be restored before any build/lint operations run. --- .github/actions/setup-frontend/action.yml | 12 ++++++++++++ .github/actions/setup-playwright/action.yml | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/actions/setup-frontend/action.yml b/.github/actions/setup-frontend/action.yml index 70af9aef5..2f78dc3eb 100644 --- a/.github/actions/setup-frontend/action.yml +++ b/.github/actions/setup-frontend/action.yml @@ -23,6 +23,18 @@ runs: cache: 'pnpm' cache-dependency-path: './pnpm-lock.yaml' + # Restore tool caches before running any build/lint operations + - name: Restore tool output cache + uses: actions/cache/restore@v4 + with: + path: | + ./.cache + ./tsconfig.tsbuildinfo + key: tool-cache-${{ runner.os }}-${{ hashFiles('./pnpm-lock.yaml') }}-${{ hashFiles('./src/**/*.{ts,vue,js,mts}', './*.config.*') }} + restore-keys: | + tool-cache-${{ runner.os }}-${{ hashFiles('./pnpm-lock.yaml') }}- + tool-cache-${{ runner.os }}- + - name: Install dependencies shell: bash run: pnpm install --frozen-lockfile diff --git a/.github/actions/setup-playwright/action.yml b/.github/actions/setup-playwright/action.yml index ebe31a4e7..89629fb2c 100644 --- a/.github/actions/setup-playwright/action.yml +++ b/.github/actions/setup-playwright/action.yml @@ -26,15 +26,3 @@ runs: if: steps.cache-playwright-browsers.outputs.cache-hit == 'true' shell: bash run: pnpm exec playwright install-deps - - - name: Cache tool outputs - uses: actions/cache@v4 - with: - path: | - ./.cache - ./tsconfig.tsbuildinfo - key: playwright-setup-cache-${{ runner.os }}-${{ hashFiles('./pnpm-lock.yaml') }}-${{ hashFiles('./src/**/*.{ts,vue,js}', './*.config.*') }} - restore-keys: | - playwright-setup-cache-${{ runner.os }}-${{ hashFiles('./pnpm-lock.yaml') }}- - playwright-setup-cache-${{ runner.os }}- - playwright-tools-cache-${{ runner.os }}-