-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Build/Test Tools: Install the npm version required by package.json in GitHub Actions #13505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manzoorwanijk
wants to merge
14
commits into
WordPress:trunk
Choose a base branch
from
manzoorwanijk:update/ci-setup-npm
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b443d99
Build/Test Tools: Add a `setup-npm` composite action.
manzoorwanijk 796e95e
Build/Test Tools: Set up npm in GitHub Actions with the `setup-npm` a…
manzoorwanijk 2fa8e3b
Build/Test Tools: Add `devEngines` to `package.json`.
manzoorwanijk 86a1631
Test: Require npm 11.19.1 to exercise the installed npm in CI.
manzoorwanijk 41e0ab1
Revert "Test: Require npm 11.19.1 to exercise the installed npm in CI."
manzoorwanijk d699a1c
Build/Test Tools: Set up npm for default themes with the `setup-npm` …
manzoorwanijk dd526e9
Build/Test Tools: Gate the default theme `setup-npm` steps on the act…
manzoorwanijk 3057127
Build/Test Tools: Scope the npm cache key to the package directory.
manzoorwanijk f85a62e
Merge remote-tracking branch 'upstream/trunk' into update/ci-setup-npm
manzoorwanijk f20efa8
Build/Test Tools: Watch the `setup-npm` action in the upgrade testing…
manzoorwanijk 6bbc67d
Merge branch 'trunk' into update/ci-setup-npm
manzoorwanijk 10a79bb
Merge branch 'trunk' into update/ci-setup-npm
manzoorwanijk 47e3bd0
Merge branch 'trunk' into update/ci-setup-npm
manzoorwanijk 8b52524
Merge branch 'trunk' into update/ci-setup-npm
manzoorwanijk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: 'Set up npm' | ||
| description: 'Installs the npm version required by the devEngines field of package.json, so every job resolves dependencies identically. Keeps the bundled npm when the field is absent.' | ||
|
|
||
| inputs: | ||
| working-directory: | ||
| description: 'Optional. The directory holding the package.json to read the required npm version from. Defaults to the workspace root.' | ||
| required: false | ||
| default: '.' | ||
| cache: | ||
| description: 'Optional. Whether to restore and save the npm cache. Defaults to true.' | ||
| required: false | ||
| default: 'true' | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Install npm | ||
| id: npm | ||
| env: | ||
| WORKING_DIRECTORY: ${{ inputs.working-directory }} | ||
| run: | | ||
| 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/>=/^}" | ||
| echo "Required npm version: $NPM_VERSION" | ||
| else | ||
| echo "No devEngines.packageManager.version, keeping the bundled npm." | ||
| fi | ||
| echo "Installed npm version: $(npm --version)" | ||
|
|
||
| # 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" | ||
|
|
||
| # Scopes the cache key to this package and keeps the hashFiles patterns | ||
| # workspace-relative and free of a "./" prefix, so they match the same | ||
| # files as every other cache key. | ||
| PATH_PREFIX="" | ||
| if [ "$WORKING_DIRECTORY" != '.' ] && [ -n "$WORKING_DIRECTORY" ]; then | ||
| PATH_PREFIX="${WORKING_DIRECTORY%/}/" | ||
| fi | ||
| echo "path-prefix=$PATH_PREFIX" >> "$GITHUB_OUTPUT" | ||
| working-directory: ${{ inputs.working-directory }} | ||
| shell: bash | ||
|
|
||
| - name: Cache npm downloads | ||
| if: ${{ inputs.cache == 'true' }} | ||
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: ${{ steps.npm.outputs.cache-dir }} | ||
| key: npm-cache-${{ runner.os }}-${{ runner.arch }}-${{ steps.npm.outputs.path-prefix }}lock-${{ hashFiles(format('{0}package-lock.json', steps.npm.outputs.path-prefix), format('{0}patches/**', steps.npm.outputs.path-prefix)) }} | ||
| restore-keys: | | ||
| npm-cache-${{ runner.os }}-${{ runner.arch }}-${{ steps.npm.outputs.path-prefix }}lock- |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.