You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: cache the pnpm executable for an exact version - #98
Every run downloads the pnpm executable from the registry, including when the version is pinned exactly and the previous job downloaded the same file. On a slow registry this download takes up most of the action's time.
In one repository on 16-vCPU runners, the Installing pnpm... group took about 1s on some runs and 32–44s on others. Every job in a run was equally slow, and nothing else changed between runs. Each of those jobs paid the cost before any of its own work started.
Refs #44. That issue also covers the runtime, which the store cache already handles when cache is enabled. This PR handles only the executable.
Change
Cache key. When the version is exact, the key is pnpm-binary-<platform>-<arch>[-musl]-<version>. An exact version comes from the version input, packageManager, or a version locked in pnpm-lock.yaml. glibc and musl hosts get different executables, so the libc is part of the key. The libc is probed the same way get-pnpm probes it.
@actions/cache includes the restore path in its version, so a different dest never restores another job's directory.
Save timing.dest is saved right after get-pnpm has verified the download and the version check has passed, before runtimes or shims are installed into it. This follows the reasoning the lockfile verification cache uses for saving early.
Restore. On a later run the executable is restored instead of downloaded.
If the restored executable does not report the expected version, it is discarded and downloaded again. This covers a truncated restore or an entry that does not run on this runner.
A failed restore or save is a warning, not a job failure.
Ranges and dist-tags still resolve against the registry on every run and are not cached. The registry has to be asked first anyway, so caching them would save little.
Independent of the cache input. This is the same as the lockfile verification cache. The entry is small, it is the same for every job that pins the version, and workflows that keep the store elsewhere still benefit.
Trust
A restored executable is not checked against npm's signature again. It was checked when it was saved, and only this repository's workflow runs can write cache entries. That is the same trust the store cache already relies on. If you would rather have this opt-in or behind its own input, I'm happy to change it.
Tests
Unit tests: cache keys for an exact version, libc, and a range or dist-tag; installer behaviour on a cache miss (download and save), a hit (no download), a hit that reports the wrong version (download again and save), and a range (no cache).
e2e job (pnpm-executable-cache-hit): runs after runtime-cache-prime, which saves the 11.22.0 executable, and points registry at an address nothing listens on. The job passes only if the executable came from the cache.
pnpm test, pnpm lint, and pnpm build pass locally. dist/index.js is rebuilt.
Summary by CodeRabbit
New Features
When caching is enabled, exact pnpm versions can be reused across runs, with cache entries separated by version and platform details.
Restored executables are checked against the requested version. If a check fails, pnpm is downloaded again.
Version ranges and dist-tags are not reused from the executable cache.
Documentation
Updated the caching documentation to explain when pnpm executables are cached and how they are restored.
The installer can cache pnpm executables for exact versions. It keys the cache by version, platform, and architecture, validates a restored executable, and downloads pnpm when restoration fails or the reported version does not match. The action passes its cache input to the installer.
Changes: pnpm executable cache
Layer / File(s)
Summary
Cache keys and operations src/install-pnpm/binary-cache.ts, src/install-pnpm/binary-cache.test.mjs
Exact valid semver versions produce cache keys using the version, platform, and architecture. Restore and save operations handle unavailable results and errors. Tests cover exact versions, version ranges, and dist-tags.
When executable caching is enabled, the installer restores and validates eligible cached executables. It downloads pnpm after a cache miss or version mismatch, then saves the executable. Tests cover cache hits, misses, invalid cached executables, existing tool-cache entries, and version ranges.
Cache input and verification src/install-pnpm/run.ts, src/install-pnpm/run.test.mjs, .github/workflows/test.yaml, README.md, action.yml
The action passes its cache input to the installer. Tests check the passed option, and the workflow checks the cached executable with installation disabled. The README and action metadata document executable caching.
sequenceDiagram
participant runSelfInstaller
participant installPnpm
participant restoreBinary
participant pnpmExecutable
participant downloadAndCheck
participant saveBinary
runSelfInstaller->>installPnpm: pass cacheExecutable option
installPnpm->>restoreBinary: restore exact-version executable
restoreBinary-->>installPnpm: cache hit or miss
opt Cache hit
installPnpm->>pnpmExecutable: check reported version
pnpmExecutable-->>installPnpm: reported version
end
opt Cache miss or version mismatch
installPnpm->>downloadAndCheck: download pnpm
downloadAndCheck-->>installPnpm: downloaded executable
installPnpm->>saveBinary: save eligible executable
end
Loading
Possibly related PRs
pnpm/setup#104: Adds the tool-cache installation flow that this change extends with an Actions-cache layer.
pnpm/setup#80: Implements tool-cache reuse behavior extended by this executable cache.
pnpm/setup#88: Changes the pnpm version resolution and executable download path used by the cache flow.
Suggested reviewers:zkochan
Merge Risk: Minimal · up to 558d9
This change caches the pnpm executable for exact versions when the cache input is enabled, and it falls back to a fresh download when a restore fails or reports the wrong version. No concrete merge-blocking risk was established. The one remaining concern, an untimed version check on a restored executable, is unconfirmed and low impact.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: caching the pnpm executable for exact versions.
Docstring Coverage
Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 7 files. (3 skipped: 3 unsupported.)
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the version key, Then tucks a pnpm file away. A cache hit skips the download trail, A mismatched one gets checked anew. The workflow tests the cached tool, And hops along its happy way.
Every run downloads the pnpm executable from the registry, even when the
version is pinned exactly and the same executable was downloaded by the
previous job. On a slow registry that download dominates the action: in one
repository the "Installing pnpm" group took 1s on some runs and 32-44s on
others, for every job of the run, with nothing else changing.
When the version is exact, cache `dest` under a key made of the version,
platform, architecture and libc, right after the download is verified and
before anything else runs from it, and restore it on later runs instead of
downloading. A restored executable that does not report the expected version
is replaced by a fresh download. Ranges and dist-tags still resolve against
the registry every run.
Refs pnpm#44
…ache
The executable is cached only with `cache: true`, because a restored
executable is not checked against npm's signature again, the same trust
a restored store relies on.
Since the tool cache landed, `dest` holds links into the tool cache, so
caching `dest` would restore a dangling `dist` symlink on a new runner.
The Actions cache now holds the download as get-pnpm verified it, and
is consulted only when the tool cache misses an exact version. A
restored executable that reports the expected version is added to the
tool cache like a download, so one that does not run never becomes a
tool cache entry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thanks for this! I rebased it onto main and reworked it on top of #104, which added a tool cache for the pnpm executable. Your commit is unchanged apart from the rebase, and the rework is a separate commit, 558d99b.
Only with cache: true. A restored executable isn't checked against npm's signature again, so caching it relies on the same trust as caching the store. That's why it now follows the cache input instead of being always on.
The cache holds the download, not dest. Since #104, dest holds links into the tool cache, including a symlink for dist/. Caching dest would restore that symlink on a new runner, where it points at a directory that doesn't exist. So now:
The Actions cache is only checked when the tool cache doesn't have the exact version, so a self-hosted runner that already has it skips the Actions cache.
On a miss, get-pnpm downloads into $RUNNER_TEMP/setup-pnpm-executable (the same path in every job, because @actions/cache matches on paths), and that directory is saved right after the download is verified.
On a hit, it's restored there and must report the expected version. It is then added to the tool cache through the same atomic rename as a download, and linked into dest. A restore that doesn't run is deleted and downloaded again, so it never becomes a tool cache entry.
Other changes:
The cache key uses the tool cache's architecture name, which already has the -musl suffix, so the second libc check is gone.
readVersion moved to version.ts so that both the install check and the restore check can use it.
The tests for the cache flows are in download.test.mjs now: miss then save, hit without a download, a broken restore, a tool cache hit that skips the Actions cache, and ranges.
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
src/install-pnpm/download.ts-146-146: 1
146-146: Major · Stability & Availability · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Bound validation of a restored executable.
If a restored executable starts but never exits, readVersion never settles. The installer cannot discard the cache entry or download pnpm. This can leave every job that restores that entry waiting until its job timeout. Add a timeout to the version check so this path can use its existing fallback. Node 24 supports a timeout option for spawn. (nodejs.org)
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 968f8e72-8402-4476-ba40-487da834170f
Commits
Reviewing files that changed from the base of the PR and between d9bbb23 and 558d99b.
Files ignored due to path filters: 1
dist/index.js is excluded by !**/dist/**
Files selected for processing: 10
.github/workflows/test.yaml
README.md
action.yml
src/install-pnpm/binary-cache.test.mjs
src/install-pnpm/binary-cache.ts
src/install-pnpm/download.test.mjs
src/install-pnpm/download.ts
src/install-pnpm/run.test.mjs
src/install-pnpm/run.ts
src/install-pnpm/version.ts
Files skipped from review as they are similar to previous changes: 1
README.md
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
Review details
Context from checks skipped due to timeout: 2
GitHub Check: Greptile Review
GitHub Check: CodeRabbit
Additional context used
ast-grep (0.51.1)
src/install-pnpm/version.ts
[warning] 1-1: Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { spawn } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
zizmor (1.31.1)
.github/workflows/test.yaml
[warning] 173-176: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
[warning] 177-177: use GitHub's dedicated self-repository syntax (self-repository): use '$/...' instead of './...'
(self-repository)
Additional comments: 1
src/install-pnpm/download.ts: 1
114-114: Data Integrity & Integration
The inspected cache producer does not establish that other files can remain after the fallback download. The claimed cache contamination is therefore unsupported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every run downloads the pnpm executable from the registry, including when the version is pinned exactly and the previous job downloaded the same file. On a slow registry this download takes up most of the action's time.
In one repository on 16-vCPU runners, the
Installing pnpm...group took about 1s on some runs and 32–44s on others. Every job in a run was equally slow, and nothing else changed between runs. Each of those jobs paid the cost before any of its own work started.Refs #44. That issue also covers the runtime, which the store cache already handles when
cacheis enabled. This PR handles only the executable.Change
pnpm-binary-<platform>-<arch>[-musl]-<version>. An exact version comes from theversioninput,packageManager, or a version locked inpnpm-lock.yaml. glibc and musl hosts get different executables, so the libc is part of the key. The libc is probed the same way get-pnpm probes it.@actions/cacheincludes the restore path in its version, so a differentdestnever restores another job's directory.destis saved right after get-pnpm has verified the download and the version check has passed, before runtimes or shims are installed into it. This follows the reasoning the lockfile verification cache uses for saving early.cacheinput. This is the same as the lockfile verification cache. The entry is small, it is the same for every job that pins the version, and workflows that keep the store elsewhere still benefit.Trust
A restored executable is not checked against npm's signature again. It was checked when it was saved, and only this repository's workflow runs can write cache entries. That is the same trust the store cache already relies on. If you would rather have this opt-in or behind its own input, I'm happy to change it.
Tests
pnpm-executable-cache-hit): runs afterruntime-cache-prime, which saves the 11.22.0 executable, and pointsregistryat an address nothing listens on. The job passes only if the executable came from the cache.pnpm test,pnpm lint, andpnpm buildpass locally.dist/index.jsis rebuilt.Summary by CodeRabbit