Skip to content

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

Open
etienne-martin wants to merge 6 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 6 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

Use case

We use pnpm/action-setup with caching enabled in a shared setup action across several workflows. We set run_install: false and run pnpm install separately because some jobs only need previously built artifacts or install dependencies conditionally.

On a cache miss, the action records the expected pnpm store path, but no cache is restored. If installation is skipped, nothing creates that directory. GitHub still runs the action's post step, which currently passes the missing path to @actions/cache. That throws a Path Validation Error and fails an otherwise successful job.

This change treats a missing store as nothing to cache. It skips the save only for ENOENT and preserves other filesystem errors.

Summary

  • Skip post-job cache save when the resolved pnpm store path does not exist
  • Avoid failing cache-enabled workflows that intentionally do not create a pnpm store
  • Preserve errors other than ENOENT

Fixes #265.

Summary by CodeRabbit

Bug Fixes

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

Tests

  • Added automated coverage for successful saves, missing paths, and unexpected access errors.
  • Pull request checks now run the test suite before rebuilding distribution files.

@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: 5518e499-afc8-411e-a2e6-481e2df70934

📥 Commits

Reviewing files that changed from the base of the PR and between 93f32be and 1f3a28f.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .github/workflows/pr-check.yaml
  • package.json
  • src/cache-save/run.test.ts
  • src/cache-save/run.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Greptile Review
🔇 Additional comments (4)
src/cache-save/run.ts (1)

3-3: LGTM!

Also applies to: 15-25

src/cache-save/run.test.ts (1)

1-53: LGTM!

package.json (1)

7-7: LGTM!

Also applies to: 23-24

.github/workflows/pr-check.yaml (1)

22-25: LGTM!


📝 Walkthrough

Walkthrough

The PR validates cachePath before saveCache. Missing paths are logged and skipped. Other access errors are rethrown. Vitest tests cover these cases, and the pull-request workflow runs the test suite.

Changes

Cache path validation

Layer / File(s) Summary
Path existence check guard
src/cache-save/run.ts
Checks cachePath before saveCache. Missing paths log an informational message and skip saving. Other errors are rethrown.
Cache validation tests and execution
src/cache-save/run.test.ts, package.json, .github/workflows/pr-check.yaml
Adds Vitest coverage for cache saving and error handling. Adds the test script, Vitest dependency, and workflow test step.

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

Merge Risk: ⚪ Minimal · up to 1f3a2

The PR limits post-job cache saving to cases where the resolved PNPM cache path exists, preventing cold-cache workflows from failing; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: zkochan

Poem

A rabbit checks the cache path twice,
Missing paths receive kind advice.
Known errors stop the save with care,
Unexpected errors travel there.
Tests hop through every case! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation skips saves for missing cache paths, logs the condition, preserves other errors, and adds relevant tests for issue #265.
Out of Scope Changes check ✅ Passed The workflow, test script, dependency, and test changes directly support implementation and validation of the cache-save fix.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: skipping cache saves when the cache path is missing.
✨ 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!

@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Reviews (3): Last reviewed commit: "chore: remove test tooling" | Re-trigger Greptile

Comment thread src/cache-save/run.ts
Comment thread src/cache-save/run.ts
greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 24, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review August 24, 2026 17:40

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@mohamadpori

mohamadpori commented Aug 24, 2026 via email

Copy link
Copy Markdown

@mohamadpori

mohamadpori commented Aug 24, 2026 via email

Copy link
Copy Markdown

@etienne-martin

Copy link
Copy Markdown
Author

Hi @zkochan, all feedback is addressed and checks pass. Could you review when you have a chance?

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

Labels

None yet

Projects

None yet

3 participants