feat: cache node_modules keyed on lockfile hash to skip npm ci#1
Draft
goastler wants to merge 1 commit into
Draft
feat: cache node_modules keyed on lockfile hash to skip npm ci#1goastler wants to merge 1 commit into
goastler wants to merge 1 commit into
Conversation
Add a separate node_modules cache (exact lockfile-hash key, no fuzzy fallback) to restore_npm_cache/save_npm_cache, and skip 'npm ci' in the npm action on an exact hit. 'npm ci' wipes node_modules and reinstalls, so caching it only pays off paired with skipping the reinstall, saving ~2 min per run when the lockfile is unchanged. A miss falls back to 'npm ci', so it is always safe.
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.
What
Adds a separate
node_modulescache keyed strictly on the lockfile hash and skipsnpm cion an exact hit.restore_npm_cache: newnode_modulesrestore with keynode-modules-<os>-<arch>-<hashFiles('**/package-lock.json')>and norestore-keys(exact match only — a tree from a different lockfile would be wrong). Exposesnode-modules-cache-hitoutput.npm: skipsnpm ciwhennode-modules-cache-hit == 'true'; falls back tonpm cion a miss.save_npm_cache: saves**/node_modulesunder the same exact key, plus cleanup of stale node_modules caches.Why
npm cideletesnode_modulesand reinstalls from scratch (~2 min). Cachingnode_modulesonly pays off paired with skipping the reinstall. A miss falls back tonpm ci, so it is always safe.Caveats
save_npm_cache(run on main), readable by all PRs. Lockfile-unchanged PRs hit and skipnpm ci; lockfile-changing PRs miss until main re-primes after merge.