Repository navigation
CI: Add the setup-npm action to wp/7.1 - #84169
manzoorwanijk wants to merge 1 commit into
Conversation
Ports trunk's `.github/setup-npm` action unchanged, ahead of the change that moves `wp/7.1` to Node 24 and npm 11.18 and uses it in its workflows. Landing it first keeps the Compressed Size check working on that change: `preactjs/compressed-size-action` checks out the base branch to build it, and the action's post step then needs `.github/setup-npm` to exist there.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 PR meta 🤖🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. should paste block styles using keyboard in
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
|
||
| - name: Cache npm downloads | ||
| if: ${{ inputs.cache == 'true' }} | ||
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
There was a problem hiding this comment.
This works, but it feels fragile. The post step reads action.yml from the base branch, so any future change to this file on wp/7.1 (step id, outputs, cache key) could break Compressed Size again.
One way around it is to pass cache: 'false' in bundle-size.yml. Or alternatively we can check out to a separate path like build-plugin-zip.yml does?
Not a blocker FWIW
There was a problem hiding this comment.
Agreed. #84322 passes cache: 'false' in trunk's bundle-size.yml. This PR stays a copy of trunk's action.
| env: | ||
| WORKING_DIRECTORY: ${{ inputs.working-directory }} | ||
| run: | | ||
| NPM_VERSION="$(jq -r '.devEngines.packageManager.version // empty' package.json)" |
There was a problem hiding this comment.
Keep in mind wp/7.1 doesn't have devEngines yet, only engines.npm. So until #84161 lands, this action will keep the bundled npm and do nothing else.
There was a problem hiding this comment.
Yes, intended. This PR only makes the action exist on the base branch; #84161 adds devEngines.
|
|
||
| - name: Cache npm downloads | ||
| if: ${{ inputs.cache == 'true' }} | ||
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
There was a problem hiding this comment.
On wp/7.1, .github/setup-node/action.yml still uses cache: npm. When #84161 uses this action, we should also port the package-manager-cache: false change from trunk. Otherwise we cache the same folder twice, and setup-node may fail the devEngines check
There was a problem hiding this comment.
#84161 already ports that: trunk's setup-node action with package-manager-cache: false, and the same flag in the workflows.
| # actions/setup-node cannot restore the npm cache: it locates the | ||
| # directory with `npm config get cache`, which runs before this step | ||
| # and fails the devEngines check under the bundled npm. | ||
| echo "cache-dir=$(npm config get cache | tr -d '\r')" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
If npm config get cache fails, the step still passes and writes an empty cache-dir.
The error then shows up later in the cache step, which may be harder to debug.
Should we save to a variable first, so the step fails early?
That's the same on trunk btw, so a follow-up is fine.
There was a problem hiding this comment.
Good catch, fixed on trunk in #84322. The release branches will pick it up when they next sync with trunk's action.
| NPM_VERSION="$(jq -r '.devEngines.packageManager.version // empty' package.json)" | ||
| if [ -n "$NPM_VERSION" ]; then | ||
| # Contributors need the floor; CI stays on that major's newest release. | ||
| npm install --global "npm@${NPM_VERSION/>=/^}" |
There was a problem hiding this comment.
Changing >= to ^ means each run installs the latest npm in that major. Two jobs could end up on different npm versions. Should we pin the exact version instead? Also, >= 11.18 (with a space) would not match.
That's the same on trunk btw, so could be a follow-up
There was a problem hiding this comment.
Floating within the major is deliberate on trunk, so CI gets npm patch releases without a bump. The space is fine: semver reads ^ 11.18 as >=11.18.0 <12.0.0-0.
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: ${{ steps.npm.outputs.cache-dir }} | ||
| key: npm-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('{0}package-lock.json', steps.npm.outputs.path-prefix)) }} |
There was a problem hiding this comment.
If hashFiles finds no lockfile, the key ends with - and never changes. The cache is saved once and then never updated. Not a problem today, but maybe worth a guard. Another thing that's in trunk and we could follow up with.
There was a problem hiding this comment.
Every caller has a lockfile, so I'd leave it.
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: ${{ steps.npm.outputs.cache-dir }} | ||
| key: npm-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('{0}package-lock.json', steps.npm.outputs.path-prefix)) }} |
There was a problem hiding this comment.
The cache key does not include the npm version. After an npm upgrade we could restore a cache made by the old version. Adding npm --version to the key would avoid this. Already the case in trunk, so this is yet another follow-up
There was a problem hiding this comment.
npm's download cache uses the same format across versions. And since npm floats, adding the version would throw the cache away on every npm release.
|
Could we please hold off on merging this, unless it's urgent. I'm wrapping up work I've been doing across all the old WP branches to restore/harden the GitHub Actions workflows, and this will likely cause conflicts with the PR stack that I have prepared for 7.1. Rebasing the entire 10+ PR stack will be much more of a pain than rebasing this PR, and I'm fairly certain there will be some overlap. I am preparing a briefing document today so that we can begin to divide and conquer reviewing these stacks, so I don't think that will take much longer. |
Sure.
Thanks |
What?
See #82328, #72973
Adds trunk's
.github/setup-npmaction towp/7.1, unchanged. Nothing uses it yet.Why?
#84161 moves
wp/7.1to Node 24 and npm 11.18 and installs npm through this action. Its Compressed Size check builds the base branch withpreactjs/compressed-size-action, and the action's post step then fails whilewp/7.1lacks.github/setup-npm. Landing the action first keeps that check green; #84161 is stacked on this PR.How?
Copies
.github/setup-npm/action.ymlfrom trunk byte for byte.Testing Instructions
CI passes. The file matches trunk's copy.
Use of AI Tools
Claude Code (Opus) prepared this PR; I reviewed it.