Debug-action-cache
if [ -f "$CACHE_PATH/.last_hash" ]; then OLD_HASH=$(cat "$CACHE_PATH/.last_hash") if [ "$OLD_HASH" != "$EXPECTED_HASH" ]; then echo "⚠️ WARNING: Cache contains old hash $OLD_HASH. Stale cache detected!" else echo "✅ Hash matches expected value." fi else echo "⚠️ No hash file found inside cache. Cannot verify integrity." fi
debug-action-cache is not a standalone command but rather a diagnostic technique used to inspect, validate, and troubleshoot how GitHub Actions (or similar CI systems) save and restore cached dependencies, build artifacts, or intermediate files. It helps answer:
"Why is my cache miss happening?" or "What exactly is stored in this cache?"
It typically involves:
You expect: Restored from cache → fast builds
But reality: Cache not found, or cache saved every time debug-action-cache
Understanding cache keys, restore keys, and cache scope is critical.
Cache saves happen in the post phase of the action. Most developers miss these logs. To capture them:
- name: Save cache manually (debug mode)
if: always()
uses: actions/cache/save@v3
with:
path: node_modules
key: $ runner.os -node-$ hashFiles('package-lock.json') -debug
This isolates the save logic, allowing you to see errors like Cache size of 11.2 GB exceeds limit of 10 GB. if [ -f "$CACHE_PATH/
The silent failures are the most dangerous. Consider these scenarios:
Standard logs just show Received 0 of 0 artifacts. That is useless. To see the truth, you need step-level debug logging, specifically for the cache action.
The Scenario: A monorepo with 50 microservices. Build times suddenly jumped from 8 minutes to 40 minutes. The team assumed debug-action-cache was working because the logs showed "Cache restored". debug-action-cache is not a standalone command but rather
The Investigation:
The Fix: Implemented a validation step checking for the existence of a specific binary (if [ ! -f node_modules/.bin/webpack ]; then exit 1; fi), forcing a cache miss on failure.