fix(lint): restrict cache lock-file glob to repo root#19
Merged
Conversation
`hashFiles('**/package-lock.json')` matches lock files in subdirectories
(e.g. `frontend/package-lock.json`), but `actions/setup-node` looks for
the lock at the repo root unless `cache-dependency-path` is set. When a
repo has only a subdir lock, setup-node would set the npm cache key based
on the subdir lock then fail with "Dependencies lock file is not found".
Discovered while rolling out lint.yml across the fleet — broke the prettier
job in ~8 repos with frontend/ subdir layouts.
Restrict to root-level locks. Repos with only subdir locks now skip the
cache (slower first install, but the prettier job actually runs).
| # subdir lock files (e.g. `frontend/package-lock.json`) and would | ||
| # cause setup-node to fail with "Dependencies lock file is not found" | ||
| # when the root has no lock. Restrict to root files only. | ||
| cache: ${{ hashFiles('package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock') != '' && 'npm' || '' }} |
There was a problem hiding this comment.
Bug: yarn.lock in the hash check will trigger the same "lock file not found" error for yarn-only repos.
actions/setup-node with cache: 'npm' looks for package-lock.json or npm-shrinkwrap.json at the repo root — it does not accept yarn.lock as proof of an npm install. So a repo that has only yarn.lock at root will:
- Hash it → non-empty → expression evaluates to
'npm' setup-nodesearches forpackage-lock.json/npm-shrinkwrap.jsonat root- Neither exists → "Dependencies lock file is not found" — the exact error this PR is fixing
Since the cache type is always hardcoded to 'npm', only npm lock files should gate the check:
Suggested change
| cache: ${{ hashFiles('package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock') != '' && 'npm' || '' }} | |
| cache: ${{ hashFiles('package-lock.json', 'npm-shrinkwrap.json') != '' && 'npm' || '' }} |
|
Flagged 1 issue inline — |
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.
hashFiles('**/package-lock.json')matches lock files in subdirectories (e.g.frontend/package-lock.json), butactions/setup-nodelooks for the lock at the repo root unlesscache-dependency-pathis set. When a repo has only a subdir lock, setup-node sets the npm cache key based on the subdir lock then fails with 'Dependencies lock file is not found in /home/runner/work/REPO/REPO'.Discovered during fleet rollout — broke the prettier job in 8 repos with
frontend/subdir layouts (finsight, techrecon, dev-utils, attaxion_marketing, inbox-superpilot-marketing, marketing-platform, wxa-mcp-server, wxa_marketing).Fix: restrict
hashFilesto root-level locks. Repos with only subdir locks now skip the cache (slower first install, but the prettier job actually runs).Future improvement: expose
cache-dependency-pathas a workflow input so callers can point setup-node at their subdir lock for faster CI.