Skip to content

CI: Harden setup-npm cache handling - #84322

Open
manzoorwanijk wants to merge 5 commits into
trunkfrom
fix/setup-npm-cache-hardening
Open

manzoorwanijk wants to merge 5 commits into
trunkfrom
fix/setup-npm-cache-hardening

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

What?

Follow up to #84169. See #82328, #72973

Part of the release-process work for moving the wp/* branches to Node 24 and npm 11/12. Makes setup-npm fail early when it cannot read the npm cache directory, and moves the bundle size workflow's cache out of setup-npm.

Why?

Both came up in @tyxla's review of the wp/7.1 port of this action. An empty cache-dir output passed silently and failed later in the cache step. compressed-size-action checks out the base branch, so the cache post step runs the base branch's copy of setup-npm and breaks whenever the two copies differ.

How?

  • 645b5d5, e9e07fb: look up the cache directory only when caching, and fail if npm errors or prints nothing.
  • c9b0955, 53cb005: bundle-size.yml passes cache: 'false' and restores the same cache with its own actions/cache step.

Testing Instructions

  1. CI passes, including Compressed Size.
  2. bash -eo pipefail -c 'X="$(false | tr -d x)"; echo reached' exits 1 without printing, while the old echo "a=$(false | tr -d x)" form exits 0.

Use of AI Tools

Claude Code (Opus) wrote the change; I reviewed it.

@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Oct 8, 2026
@manzoorwanijk manzoorwanijk self-assigned this Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: -48 B (0%)

Total Size: 8.65 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 548 kB -48 B (-0.01%)

c024519 Run

@manzoorwanijk
manzoorwanijk requested review from ciampo and tyxla October 8, 2026 12:33
@manzoorwanijk
manzoorwanijk marked this pull request as ready for review October 8, 2026 12:33
@manzoorwanijk
manzoorwanijk requested a review from desrosj as a code owner October 8, 2026 12:33
Comment thread .github/setup-npm/action.yml Resolved
Comment thread .github/setup-npm/action.yml Resolved
Comment thread .github/workflows/bundle-size.yml Resolved
Comment thread .github/workflows/bundle-size.yml Resolved
@manzoorwanijk
manzoorwanijk requested a review from tyxla October 9, 2026 11:00

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good, the only thing from my perspective is this one.

Should we get feedback from @desrosj too?

@manzoorwanijk

Copy link
Copy Markdown
Member Author

Should we get feedback from @desrosj too?

Yes, let us wait for his review.

The cache directory was written straight from a command substitution
inside echo, whose exit status ignores the substitution. A failing
`npm config get cache` left the step green with an empty cache-dir
output, and the error only surfaced later in the cache step. Assigning
it to a variable first lets the shell's pipefail stop the step there.
compressed-size-action checks out the base branch to measure it, so
the actions/cache post step registered by setup-npm runs against the
base branch's copy of the action. Any change to that action on one
side, or its absence on an old release branch, breaks the job. The
cache only saves download time here, so turn it off.
Jobs that pass `cache: 'false'` never read the cache-dir output, so a
failing lookup should not fail them now that the step stops on it. An
npm that exits 0 but prints nothing would still leave the output empty,
so fail on that too.
With setup-npm's cache off, the job ran `npm ci` for both the head and
the base branch without any cache, which is slower and more exposed to
registry hiccups. A workflow level actions/cache step restores the
same cache, and its post step comes from the downloaded action rather
than this repository, so checking out the base branch cannot break it.
@manzoorwanijk
manzoorwanijk force-pushed the fix/setup-npm-cache-hardening branch from 0e2c2a6 to c024519 Compare November 13, 2026 10:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants