refactor: introduce restore keys for cache by SukkaW · Pull Request #280 · pnpm/action-setup · GitHub
Skip to content

refactor: introduce restore keys for cache - #280

Merged
zkochan merged 3 commits into
pnpm:masterfrom
SukkaW:cache-restore-keys
Aug 3, 2026
Merged

zkochan merged 3 commits into
pnpm:masterfrom
SukkaW:cache-restore-keys

Conversation

@SukkaW

@SukkaW SukkaW commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Add restoreKeys for restoring the store cache.

The idea is that we currently include the pnpm-lock.yaml content hash within the cache primary key. This means even if only one dependency has changed, the entire pnpm-lock.yaml content hash changes, and the entire pnpm store cache is now thrown away.

But we don't have to invalidate the entire store. Other dependencies' cache may still be utilized. We can still restore the previous store cache, and only the changed dependencies need to be and will be downloaded.

restoreKeys doesn't change the fact that the cache is still miss (primaryKey), so during the post action we still upload the latest pnpm store to a new cache entry.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved dependency cache restoration by allowing partially matching pnpm caches to be reused when an exact cache match is unavailable.
    • Corrected cache-hit reporting so dependencies are reinstalled when the lockfile changes, even if a partial cache is restored.

@SukkaW
SukkaW requested a review from zkochan as a code owner July 31, 2026 17:47
@qodo-code-review

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 31, 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: e40af624-40f5-47fd-a983-8dcd8295f53c

📥 Commits

Reviewing files that changed from the base of the PR and between 13bdc8a and 0adcde8.

⛔ Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
📒 Files selected for processing (1)
  • src/cache-restore/run.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cache-restore/run.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Smoke (windows / v9.15.5)
  • GitHub Check: Standalone Windows self-update (PATH regression)

📝 Walkthrough

Walkthrough

runRestoreCache now passes an OS and architecture based pnpm cache-key prefix to restoreCache. It reports cache-hit only when the restored key exactly matches the primary key.

Changes

Cache restore fallback

Layer / File(s) Summary
Add restore-key prefix and exact-hit reporting
src/cache-restore/run.ts
runRestoreCache passes a runner-specific pnpm restore-key prefix and reports cache-hit only for an exact primary-key match. Partial cache restoration remains available.

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

Suggested reviewers: zkochan

Poem

A rabbit checks the cache with care,
An exact key marks treasure there.
By OS and arch, fallback runs,
Then fresh installs start when needed.
Hop, restore, and build with cheer!

🚥 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 the main change: adding restore keys for cache restoration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cache-restore/run.ts`:
- Around line 21-27: Update the cache-hit handling around restoreCache in run so
it reports true only when the returned cache key exactly equals primaryKey;
preserve restoring contents for restoreKeys prefix matches while returning
cache-hit=false. Add a regression test covering a restore-key match and
verifying dependency installation remains reachable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c1c1d484-d0ad-4c1c-94f4-21b1ec789dac

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebf471 and 13bdc8a.

📒 Files selected for processing (1)
  • src/cache-restore/run.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Standalone Windows self-update (PATH regression)
⚠️ CI failures not shown inline (2)

GitHub Actions: pr-check / 0_check-dist.txt: refactor: introduce restore keys for cache

Conclusion: failure

View job details

##[group]Run git diff --exit-code dist/index.js
 �[36;1mgit diff --exit-code dist/index.js�[0m
 shell: /usr/bin/bash -e {0}
 env:
   PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
 ##[endgroup]
 diff --git a/dist/index.js b/dist/index.js
 index 1866127..b11810d 100644
 Binary files a/dist/index.js and b/dist/index.js differ
 ##[error]Process completed with exit code 1.

GitHub Actions: pr-check / check-dist: refactor: introduce restore keys for cache

Conclusion: failure

View job details

##[group]Run git diff --exit-code dist/index.js
 �[36;1mgit diff --exit-code dist/index.js�[0m
 shell: /usr/bin/bash -e {0}
 env:
   PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
 ##[endgroup]
 diff --git a/dist/index.js b/dist/index.js
 index 1866127..b11810d 100644
 Binary files a/dist/index.js and b/dist/index.js differ
 ##[error]Process completed with exit code 1.
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-05-11T12:04:07.383Z
Learnt from: zkochan
Repo: pnpm/action-setup PR: 256
File: src/install-pnpm/run.ts:150-166
Timestamp: 2026-05-11T12:04:07.383Z
Learning: In pnpm/action-setup, when validating or forwarding the version value used for `pnpm self-update` and/or `devEngines.packageManager.version`, do not restrict it to exact versions or tags only—pnpm supports semver ranges for these inputs. Ensure any code that parses/validates `devEngines.packageManager.version` (and the value passed to `pnpm self-update`) allows range syntax such as `^`, `~`, and comparators (e.g. `>=8 <10`) instead of rejecting anything that isn’t a single exact version. Note: the plain `packageManager` field is different, so apply this “allow semver ranges” rule specifically to `devEngines.packageManager.version` / `self-update` handling.

Applied to files:

  • src/cache-restore/run.ts

Comment thread src/cache-restore/run.ts

@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.

@SukkaW

SukkaW commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@zkochan
zkochan merged commit 769ae71 into pnpm:master Aug 3, 2026
21 checks passed
dbmikus pushed a commit to gofixpoint/amika that referenced this pull request Oct 23, 2026
Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 5.0.0 to 6.1.0.

## Release notes

Sourced from pnpm/action-setup's releases.

### v6.1.0

### What's Changed
- feat: support pnpm v12 by `@zkochan` in pnpm/action-setup#288

Full Changelog: pnpm/action-setup@v6.0.10...v6.1.0

### v6.0.10

### What's Changed
- docs(README): point users to the successor pnpm/setup action by `@BlackHole1` in pnpm/action-setup#282
- refactor: introduce restore keys for cache by `@SukkaW` in pnpm/action-setup#280
- ci: use pnpm 11 for `pr-check` by `@jamietanna` in pnpm/action-setup#284
- fix: update pnpm to v11.19.0 by `@jamietanna` in pnpm/action-setup#283
- docs: update README to include devEngines.packageManager by `@nemchik` in pnpm/action-setup#273

### New Contributors
- `@jamietanna` made their first contribution in pnpm/action-setup#284
- `@nemchik` made their first contribution in pnpm/action-setup#273

Full Changelog: pnpm/action-setup@v6...v6.0.10

### v6.0.9

### What's Changed
- fix: update pnpm to v11.7.0 by `@zkochan` in pnpm/action-setup#267

Full Changelog: pnpm/action-setup@v6...v6.0.9

### v6.0.8

### What's Changed
- docs(README): fix `cache_dependency_path` type by `@haines` in pnpm/action-setup#257
- fix: drop patchPnpmEnv so standalone+self-update works on Windows by `@zkochan` in pnpm/action-setup#258
- fix: update pnpm to 11.1.1 by `@mungodewar` in pnpm/action-setup#248

### New Contributors
- `@mungodewar` made their first contribution in pnpm/action-setup#248

Full Changelog: pnpm/action-setup@v6.0.7...v6.0.8

### v6.0.7

### What's Changed
- fix: honor devEngines.packageManager.onFail=error (#252) by `@zkochan` in pnpm/action-setup#254
- fix: restore inputs from state in post by `@haines` in pnpm/action-setup#255
- fix: self-update bootstrap to packageManager-pinned version (#233) by `@zkochan` in pnpm/action-setup#256

### New Contributors
- `@haines` made their first contribution in pnpm/action-setup#255

Full Changelog: pnpm/action-setup@v6.0.6...v6.0.7

... (truncated)

## Commits
- `ea17c68` feat: support pnpm v12 (#288)
- `0977fd9` docs: Update README to include devEngines.packageManager (#273)
- `48261ac` fix: update pnpm to v11.19.0 (#283)
- `75677f7` ci: use pnpm 11 for `pr-check` (#284)
- `769ae71` refactor: introduce restore keys for cache (#280)
- `6fed91f` docs(README): point users to the successor pnpm/setup action (#282)
- `0ebf471` fix: update pnpm to v11.7.0 (#267)
- `0e279bb` fix: update pnpm to 11.1.1 (#248)
- `3e83581` fix: drop patchPnpmEnv so standalone+self-update works on Windows (#258)
- `551b42e` docs(README): fix `cache_dependency_path` type (#257)
- Additional commits viewable in compare view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants