Skip to content

fix(lint): restrict cache lock-file glob to repo root#19

Merged
topcoder1 merged 1 commit into
mainfrom
fix/lint-cache-subdir-lock
May 2, 2026
Merged

fix(lint): restrict cache lock-file glob to repo root#19
topcoder1 merged 1 commit into
mainfrom
fix/lint-cache-subdir-lock

Conversation

@topcoder1

Copy link
Copy Markdown
Owner

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 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 hashFiles to 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-path as a workflow input so callers can point setup-node at their subdir lock for faster CI.

`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' || '' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Hash it → non-empty → expression evaluates to 'npm'
  2. setup-node searches for package-lock.json / npm-shrinkwrap.json at root
  3. 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' || '' }}

@claude

claude Bot commented May 1, 2026

Copy link
Copy Markdown

Flagged 1 issue inline — yarn.lock in the hashFiles list will re-trigger the same "lock file not found" error for yarn-only repos when cache is hardcoded to 'npm'.

@topcoder1
topcoder1 merged commit 7908889 into main May 2, 2026
4 checks passed
@topcoder1
topcoder1 deleted the fix/lint-cache-subdir-lock branch May 2, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant