With this key, what makes the job save a fresh cache entry?
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
- Any push to the main branch
- Any new commit to the repo
- A version bump in package.json
- A change to the lockfile
hashFiles fingerprints the lockfile, so the key, and therefore a new cache, changes only when the resolved dependencies do; otherwise the existing entry is restored.
Play DevOps ▸