Repository navigation
Conversation
npm checks devEngines.packageManager from the workspace package.json even for `npm config get cache`, so setup-node fails before the workflow can install the required package manager (monorepos with pnpm at the root, or projects that require a newer npm than the one bundled with Node). Retry the lookup once with --force only when npm reports EBADDEVENGINES; the normal path is unchanged. Fixes actions#1553 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the npm cache lookup retry change.
No open issues 🎉
What changed in this PR
This PR addresses #1553 by allowing setup-node’s npm cache lookup to recover from EBADDEVENGINES, so workflows can proceed before installing the required package manager.
Changes:
- Retry
npm config get cacheonce with--forceonly after anEBADDEVENGINESfailure, preserving other error handling. - Add four unit tests covering normal lookup, retry success, unrelated errors, and retry failure.
- Update both bundled action entrypoints with the retry logic.
| File | Description |
|---|---|
src/cache-utils.ts |
Adds the conditional npm cache lookup retry and informational log. |
dist/setup/index.js |
Includes the retry logic in the setup bundle. |
dist/cache-save/index.js |
Includes the retry logic in the cache-save bundle. |
__tests__/cache-utils.test.ts |
Tests successful lookups and retry/error behavior. |
Review effort: Balanced
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
With npm caching enabled, setup-node looks up the cache folder with
npm config get cachein the workspace root. npm checksdevEngines.packageManagerfrom thatpackage.jsoneven for this read-only command, and exits withEBADDEVENGINESwhen the installed npm doesn't match. setup-node then fails before the workflow can install the package manager the project asks for.This affects the three cases reported in #1553:
^11.10.0on Node 22,>=12.2.2on any current Node);pnpmdeclared at the root and an npm project in a subfolder. This one fails on npm 11 as well, because npm still rejects a package-manager name mismatch.The change keeps the current lookup as is. Only when it fails with
EBADDEVENGINESdoes setup-node log a short note and retry once withnpm config get cache --force.--forceturns the devEngines check into a warning and still honours a project.npmrccache=setting. Any other error, or a failing retry, is reported as before.I didn't add
--forceunconditionally because npm then printsnpm warn using --force Recommended protections disabled.for every project. I checked that on Node 18, 20, 22, 24 and 26, so every npm-cached job would show it.Testing
__tests__/cache-utils.test.ts(normal path doesn't use--force,EBADDEVENGINEStriggers one retry, other errors don't retry, a failing retry surfaces its error). The full suite ran 10 times innode:24: 261/261 passed each time.format-check,lintandbuildare clean, anddist/was rebuilt.ubuntu-24.04: eran132/setup-node-devengines-repro, run. 4 scenarios × Node 22/24/26 × 10 attempts, comparing upstream v7.1.0 with this branch. Jobs using this branch have nocontinue-on-error, so the post-job cache save passes as well:^11.10.0app/>=12.2.2--forcewarningRelated issue:
Fixes #1553
Check list:
🤖 Generated with Claude Code