Skip to content

fix: skip cache save when path is missing - #266

Open
etienne-martin wants to merge 3 commits into
pnpm:masterfrom
sudden-network:fix/cache-save-missing-path
Open

fix: skip cache save when path is missing#266
etienne-martin wants to merge 3 commits into
pnpm:masterfrom
sudden-network:fix/cache-save-missing-path

Conversation

@etienne-martin

@etienne-martin etienne-martin commented Jun 11, 2026

Copy link
Copy Markdown

Summary

  • Skip post-job cache save when the resolved PNPM cache path does not exist
  • Avoid failing cold-cache workflows that restore cache but never create a PNPM store

Fixes #265.

Validation

  • pnpm install --frozen-lockfile
  • pnpm run build
  • pnpm exec tsc --noEmit

Summary by CodeRabbit

Bug Fixes

  • Cache operations now verify cache path accessibility before saving and gracefully handle unavailable paths with an informational message.

@etienne-martin
etienne-martin requested a review from zkochan as a code owner June 11, 2026 18:09
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ef79fbf-c9f5-434a-9b0c-d64b53906d94

📥 Commits

Reviewing files that changed from the base of the PR and between 49997ca and 93f32be.

⛔ Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • src/cache-save/run.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cache-save/run.ts

📝 Walkthrough

Walkthrough

The PR adds an asynchronous cachePath access check to runSaveCache. If access fails, the function logs an informational message and exits before calling saveCache.

Changes

Cache path existence check

Layer / File(s) Summary
Path existence check guard
src/cache-save/run.ts
Imports access from fs/promises. The guard checks cachePath before saveCache; failed checks log an informational message and return early.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: zkochan

Poem

A rabbit checks the cache path twice,
Then skips a save when access denies.
A quiet log records the way,
No cold-cache error ends the day.
Hop, hop—safe cleanup today! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes skipping cache saves when the cache path is missing.
Linked Issues check ✅ Passed The change checks cachePath access and exits before saveCache when the path is missing, which addresses issue #265.
Out of Scope Changes check ✅ Passed The reviewed change is limited to preventing cache saves for inaccessible paths and is related to issue #265.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Skip cache save when PNPM store path is missing
🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

Walkthroughs

Description
• Skip post-job cache save when the resolved cache path does not exist.
• Prevent cold-cache workflows from failing when pnpm store is never created.
• Regenerate the bundled action output to include the new guard.
Diagram
graph TD
  A["GitHub Actions job"] --> B["Restore cache"] --> C["runSaveCache()"] --> D{"Primary key hit?"}
  D -- "Yes" --> E["Skip save"]
  D -- "No" --> F{"Cache path exists?"}
  F -- "No" --> E
  F -- "Yes" --> G["saveCache()"] --> H["GitHub Cache"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Try/catch around saveCache() and treat ENOENT as non-fatal
  • ➕ Avoids an extra filesystem check
  • ➕ Centralizes error-handling around the call that can fail
  • ➖ Requires inspecting error shapes/codes across runners/node versions
  • ➖ Harder to ensure only missing-path errors are suppressed
2. Ensure pnpm store directory exists before saving (mkdir -p)
  • ➕ Allows saving an empty store directory (if desired)
  • ➕ May simplify downstream logic if empty cache artifacts are acceptable
  • ➖ Could create empty cache entries and waste cache quota/time
  • ➖ Changes behavior beyond 'do not fail' (creates filesystem side effects)

Recommendation: The current existsSync(path) guard is the simplest and most predictable fix: it prevents a known failure mode (missing store directory) without altering cache contents or error semantics for other failures. The alternatives add complexity or introduce new side effects (saving empty caches).

Grey Divider

File Changes

Bug fix (1)
run.ts Guard cache save when the resolved cache path is missing +6/-0

Guard cache save when the resolved cache path is missing

• Imports fs.existsSync and skips calling @actions/cache.saveCache when the resolved cache path does not exist. Logs an informational message explaining why the save was skipped.

src/cache-save/run.ts


Other (1)
index.js Regenerate bundled action output with missing-path cache-save guard +111/-111

Regenerate bundled action output with missing-path cache-save guard

• Updates the compiled distribution bundle to include the new existsSync(cachePath) check and log message in the post-job cache save codepath.

dist/index.js


Grey Divider

Qodo Logo

@BlackHole1 BlackHole1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I prefer to use the promise method here rather than the synchronous method.

@etienne-martin

Copy link
Copy Markdown
Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants