What the numbers show
cache steps ≥ 30s or ≥ 10% of the jobA cache that misses, is keyed on a file that changes every commit, or is so large that downloading it takes minutes adds wait instead of removing it. Check the hit rate in the step log before tuning anything else.
The change
Key the cache on the lockfile, with a fallback
- uses: actions/cache@v4 with: path: ~/.npm key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }} restore-keys: npm-${{ runner.os }}-Or use a runner with warm machines
- runs-on: ubuntu-latest+ runs-on: graphideRunner options
Verify the verdict stays the same
- 01The cache step logs a hit on the second run of the same lockfile.
- 02The job's conclusion matches with and without the cache.
- 03Clear the cache once and confirm a cold run still passes.