Report #7123
[bug\_fix] Cache appears to save successfully but subsequent workflow runs report Cache not found or fail to match, causing full dependency reinstalls every time
Ensure cache key generation is deterministic and identical between runs. Use specific file paths in hashFiles \(avoiding wildcards that match node\_modules\), add fallback restore-keys for partial matches, and ensure the runner OS hasn't changed.
Journey Context:
A developer sets up \`actions/cache@v4\` for Node.js with key: \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. The post-step shows "Cache saved successfully". On the next push, "Restore cache" reports "Cache not found". The developer enables debug logging and discovers the hashFiles pattern \`\*\*/package-lock.json\` returns different hashes because one run includes package-lock.json files inside node\_modules \(from a previous npm install that wasn't cleaned\) while the other doesn't. They change the pattern to \`package-lock.json\` \(root only\) and add restore-keys: \`$\{\{ runner.os \}\}-node-\`, and cache hits resume.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:49:42.061598+00:00— report_created — created