Cache by default (mirror setup-node) + DX fixes#4
Merged
Conversation
Mirror actions/setup-node's default-on caching: add a package-manager-cache input (default true) and change cache to auto-enable when the project looks installable (a lockfile, or a package.json packageManager/devEngines field). An explicit cache value still wins; package-manager-cache: false (or cache: false) disables. Previously caching required opt-in cache: true, which silently gave drop-in migrators no caching. Also add three low-risk DX inputs drawn from top actions/setup-node issues: - working-directory: resolve the Node pin and lockfile from a subdirectory, for monorepos (setup-node#706). - cache-key-prefix: inject a prefix segment into the cache key to scope or bust caches independently of the lockfile (setup-node#1320). - fold the project's Node pin into the cache key so a Node-version bump invalidates the stale toolchain cache (setup-node#1171). Extend smoke.yml with jobs asserting caching auto-enables by default on a lockfile project and that package-manager-cache: false disables it. Update README and action.yml input docs.
The cache-default-on smoke job asserted on cache-hit to detect whether caching was active, but actions/cache sets cache-hit to an empty string on a full miss (always the case on a first CI run) even when caching is enabled and the cache will be saved at job end. The auto-enable implementation was correct — the cache step ran and reported a miss — but the assertion was wrong. Add a caching-enabled action output sourced from the resolved cache decision (steps.cacheflag.outputs.enabled), independent of whether a cache was hit, and assert on it in both the auto-enable and disable smoke jobs. Document the new output and clarify cache-hit's miss-is-empty semantics in the README.
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.
Cache by default (mirror setup-node)
actions/setup-nodeenables caching by default via itspackage-manager-cacheinput (defaulttrue) — caching turns on whenever the project looks installable. setup-nub previously required opt-incache: true, so drop-in migrators silently got zero caching. This PR mirrors setup-node:package-manager-cacheinput (defaulttrue) — the disable knob, same name/semantics as setup-node.cachedefault changed from"false"to""(unset). Caching now auto-enables when a lockfile (pnpm-lock.yaml,package-lock.json,bun.lock/bun.lockb,yarn.lock) is present, orpackage.jsondeclares apackageManager/devEnginesfield.cachevalue wins (a setup-node PM name likenpm/pnpmis still accepted and treated as truthy) → elsepackage-manager-cache: falsedisables → else auto-detect.cache: false/package-manager-cache: falsedisables;cache: npm/pnpm/yarnenables.The cached set (nub's CAS store, the
nodetoolchain dir, the PM packument cache), keyed on OS/arch + lockfile hash with arestore-keysladder, is unchanged — only the default flips on plus the disable knob is added.Smoke jobs added
cache-default-on— a lockfile project with nocache:input asserts caching auto-enabled (cache-hitoutput is a defined boolean).cache-disable—package-manager-cache: falseon a lockfile project asserts caching disabled (cache-hitoutput empty).DX fixes (clear, low-risk wins from top setup-node issues)
Folded in alongside the cache change:
working-directoryinput (setup-node #706, 47 reactions) — resolve the Node pin + lockfile from a subdirectory, for monorepos. setup-node has no first-class support for this; it's a recurring monorepo papercut.cache-key-prefixinput (setup-node #1320) — inject a prefix segment into the cache key to scope/bust caches independently of the lockfile..node-version/.nvmrc), so a Node-version bump invalidates the stale toolchain cache instead of restoring it.Already handled by setup-nub today (no change needed, noted for context):
cache: yarn/pnpmfails (setup-node #1027, #1357) — setup-nub normalizes any PM name to a single boolean store, so these never fail..node-versionby default (setup-node #683) — setup-nub already eager-provisions from the full pin chain with no input.restore-keysladder.node-version-fileabsolute paths (setup-node #852) — setup-nub's provision reads the file by path directly; absolute paths work.Recommended but NOT implemented (maintainer decisions / larger features)
Prioritized by upstream demand. These are product/default calls or non-trivial features — flagged for your decision, not landed here:
save-always-style behavior (oractions/cache/restore+actions/cache/savewithif: always()) would save partial-install progress. A behavior-default decision.scopedefaults to package.json scope (setup-node #128). Small, but it's an auth-default behavior change — recommend maintainer sign-off.mise/.tool-versionssupport (setup-node #1304). Depends on nub's own pin-resolution chain; align with nub core before adding here.Verification
actionlint -shellcheck=shellcheck .github/workflows/smoke.yml— no new findings (4 pre-existing infos/warnings unchanged: SC2193 from[[ == ]]expression substitution, SC2016 from literal${NODE_AUTH_TOKEN}in auth jobs).action.ymlandsmoke.ymlparse as valid YAML.