mirror of
https://github.com/actions/setup-node.git
synced 2026-06-23 15:04:06 +08:00
Compare commits
2 Commits
v6.0.0
...
7a30b27101
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a30b27101 | ||
|
|
470d7fe388 |
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@@ -16,4 +16,4 @@ jobs:
|
|||||||
name: Check dist/
|
name: Check dist/
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '20.x'
|
||||||
|
|||||||
66
.github/workflows/e2e-cache.yml
vendored
66
.github/workflows/e2e-cache.yml
vendored
@@ -18,8 +18,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Clean global cache
|
- name: Clean global cache
|
||||||
@@ -41,8 +41,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Install pnpm
|
- name: Install pnpm
|
||||||
@@ -74,8 +74,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Yarn version
|
- name: Yarn version
|
||||||
@@ -106,8 +106,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Update yarn
|
- name: Update yarn
|
||||||
@@ -139,7 +139,7 @@ jobs:
|
|||||||
name: Test yarn subprojects
|
name: Test yarn subprojects
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -166,7 +166,7 @@ jobs:
|
|||||||
name: Test yarn subprojects all locally managed
|
name: Test yarn subprojects all locally managed
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -193,7 +193,7 @@ jobs:
|
|||||||
name: Test yarn subprojects some locally managed
|
name: Test yarn subprojects some locally managed
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -220,7 +220,7 @@ jobs:
|
|||||||
name: Test yarn subprojects managed by git
|
name: Test yarn subprojects managed by git
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -244,14 +244,14 @@ jobs:
|
|||||||
sub2/*.lock
|
sub2/*.lock
|
||||||
sub3/*.lock
|
sub3/*.lock
|
||||||
|
|
||||||
node-npm-packageManager-auto-cache:
|
node-npm-package-manager-cache:
|
||||||
name: Test auto cache with top-level packageManager
|
name: Test enabling cache if package manager field is present (Node ${{ matrix.node-version }}, ${{ matrix.os }})
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Create package.json with packageManager field
|
- name: Create package.json with packageManager field
|
||||||
@@ -268,37 +268,3 @@ jobs:
|
|||||||
- name: Verify node and npm
|
- name: Verify node and npm
|
||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
node-npm-devEngines-auto-cache:
|
|
||||||
name: Test auto cache with devEngines.packageManager
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
|
||||||
node-version: [20, 22, 24]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
- name: Create package.json with devEngines field
|
|
||||||
run: |
|
|
||||||
echo '{
|
|
||||||
"name": "test-project",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"devEngines": {
|
|
||||||
"packageManager": {
|
|
||||||
"name": "npm",
|
|
||||||
"onFail": "error"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > package.json
|
|
||||||
- name: Clean global cache
|
|
||||||
run: npm cache clean --force
|
|
||||||
- name: Setup Node with caching enabled
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm install
|
|
||||||
- name: Verify node and npm
|
|
||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
|
||||||
shell: bash
|
|
||||||
|
|||||||
12
.github/workflows/proxy.yml
vendored
12
.github/workflows/proxy.yml
vendored
@@ -28,12 +28,12 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Clear tool cache
|
- name: Clear tool cache
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
- name: Setup node 24
|
- name: Setup node 14
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 14.x
|
||||||
- name: Verify node and npm
|
- name: Verify node and npm
|
||||||
run: __tests__/verify-node.sh 24
|
run: __tests__/verify-node.sh 14
|
||||||
|
|
||||||
test-bypass-proxy:
|
test-bypass-proxy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -44,9 +44,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Clear tool cache
|
- name: Clear tool cache
|
||||||
run: rm -rf $RUNNER_TOOL_CACHE/*
|
run: rm -rf $RUNNER_TOOL_CACHE/*
|
||||||
- name: Setup node 24
|
- name: Setup node 11
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 11
|
||||||
- name: Verify node and npm
|
- name: Verify node and npm
|
||||||
run: __tests__/verify-node.sh 24
|
run: __tests__/verify-node.sh 11
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.4.0
|
uses: actions/publish-action@v0.3.0
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|||||||
36
.github/workflows/versions.yml
vendored
36
.github/workflows/versions.yml
vendored
@@ -17,8 +17,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-13]
|
||||||
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
|
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
@@ -56,7 +56,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version:
|
node-version:
|
||||||
[
|
[
|
||||||
'20-v8-canary',
|
'20-v8-canary',
|
||||||
@@ -81,8 +81,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20-nightly, 25-nightly, 24.0.0-nightly]
|
node-version: [20-nightly, 21-nightly, 18.0.0-nightly]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -101,8 +101,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20.0.0-rc.1, 22.14.0-rc.1, 24.0.0-rc.4]
|
node-version: [20.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -121,8 +121,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20.10.0, 22.0.0, 24.9.0]
|
node-version: [18.20.0, 20.10.0, 22.0.0]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
@@ -138,8 +138,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [20, 22, 24]
|
node-version: [18, 20, 22, 24]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup Node and check latest
|
- name: Setup Node and check latest
|
||||||
@@ -156,7 +156,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version-file:
|
node-version-file:
|
||||||
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
||||||
steps:
|
steps:
|
||||||
@@ -173,7 +173,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
@@ -188,7 +188,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
@@ -203,7 +203,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [17, 19]
|
node-version: [17, 19]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
@@ -220,7 +220,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
# test old versions which didn't have npm and layout different
|
# test old versions which didn't have npm and layout different
|
||||||
@@ -250,7 +250,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version: [current, latest, node]
|
node-version: [current, latest, node]
|
||||||
steps:
|
steps:
|
||||||
- name: Get node version
|
- name: Get node version
|
||||||
|
|||||||
28
README.md
28
README.md
@@ -12,14 +12,10 @@ This action provides the following functionality for GitHub Actions users:
|
|||||||
- Registering problem matchers for error output
|
- Registering problem matchers for error output
|
||||||
- Configuring authentication for GPR or npm
|
- Configuring authentication for GPR or npm
|
||||||
|
|
||||||
## Breaking changes in V6
|
|
||||||
|
|
||||||
- Caching is now automatically enabled for npm projects when either the `devEngines.packageManager` field or the top-level `packageManager` field in `package.json` is set to `npm`. For other package managers, such as Yarn and pnpm, caching is disabled by default and must be configured manually using the `cache` input.
|
|
||||||
|
|
||||||
## Breaking changes in V5
|
## Breaking changes in V5
|
||||||
|
|
||||||
- Enabled caching by default with package manager detection if no cache input is provided.
|
- Enabled caching for npm dependencies by default when the package manager is detected and no cache input is provided.
|
||||||
> For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation.
|
> For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching for npm by setting `package-manager-cache: false` when caching is not needed for secure operation.
|
||||||
|
|
||||||
- Upgraded action from node20 to node24.
|
- Upgraded action from node20 to node24.
|
||||||
> Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. [See Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1)
|
> Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. [See Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1)
|
||||||
@@ -32,7 +28,7 @@ See [action.yml](action.yml)
|
|||||||
|
|
||||||
<!-- start usage -->
|
<!-- start usage -->
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
# Version Spec of the version to use in SemVer notation.
|
# Version Spec of the version to use in SemVer notation.
|
||||||
# It also admits such aliases as lts/*, latest, nightly and canary builds
|
# It also admits such aliases as lts/*, latest, nightly and canary builds
|
||||||
@@ -71,7 +67,7 @@ See [action.yml](action.yml)
|
|||||||
# Default: ''
|
# Default: ''
|
||||||
cache: ''
|
cache: ''
|
||||||
|
|
||||||
# Controls automatic caching for npm. By default, caching for npm is enabled if either the devEngines.packageManager field or the top-level packageManager field in package.json specifies npm and no explicit cache input is provided.
|
# Controls automatic caching for npm. By default, caching for npm is enabled if the packageManager field in package.json specifies npm and no explicit cache input is provided.
|
||||||
# To disable automatic caching for npm, set package-manager-cache to false.
|
# To disable automatic caching for npm, set package-manager-cache to false.
|
||||||
# default: true
|
# default: true
|
||||||
package-manager-cache: true
|
package-manager-cache: true
|
||||||
@@ -118,7 +114,7 @@ See [action.yml](action.yml)
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 24
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -139,7 +135,7 @@ Examples:
|
|||||||
|
|
||||||
- Major versions: `22`, `24`
|
- Major versions: `22`, `24`
|
||||||
- More specific versions: `20.19`, `22.17.1` , `24.8.0`
|
- More specific versions: `20.19`, `22.17.1` , `24.8.0`
|
||||||
- NVM LTS syntax: `lts/iron`, `lts/jod`, `lts/*`, `lts/-n`
|
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
|
||||||
- Latest release: `*` or `latest`/`current`/`node`
|
- Latest release: `*` or `latest`/`current`/`node`
|
||||||
|
|
||||||
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
|
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
|
||||||
@@ -167,7 +163,7 @@ See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` in
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 24
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -180,7 +176,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 24
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -189,14 +185,14 @@ steps:
|
|||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
Caching for npm dependencies is automatically enabled when your `package.json` contains either `devEngines.packageManager` field or top-level `packageManager` field set to `npm`, and no explicit cache input is provided.
|
Caching for npm dependencies is automatically enabled when your `package.json` contains a `packageManager` field set to `npm` and no explicit cache input is provided.
|
||||||
|
|
||||||
This behavior is controlled by the `package-manager-cache` input, which defaults to `true`. To turn off automatic caching, set `package-manager-cache` to `false`.
|
This behavior is controlled by the `package-manager-cache` input, which defaults to `true`. To turn off automatic caching, set `package-manager-cache` to `false`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
package-manager-cache: false
|
package-manager-cache: false
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -216,7 +212,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -230,7 +226,7 @@ jobs:
|
|||||||
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
node-version: 24
|
node-version: 24
|
||||||
|
|||||||
@@ -285,12 +285,13 @@ describe('main tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('cache feature tests', () => {
|
describe('cache feature tests', () => {
|
||||||
it('Should enable caching when packageManager is npm and cache input is not provided', async () => {
|
it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => {
|
||||||
inputs['package-manager-cache'] = 'true';
|
inputs['package-manager-cache'] = 'true';
|
||||||
inputs['cache'] = '';
|
inputs['cache'] = ''; // No cache input is provided
|
||||||
isCacheActionAvailable.mockImplementation(() => true);
|
isCacheActionAvailable.mockImplementation(() => true);
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
readFileSpy.mockImplementation(() =>
|
readFileSpy.mockImplementation(() =>
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -303,106 +304,16 @@ describe('main tests', () => {
|
|||||||
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should enable caching when devEngines.packageManager.name is "npm" and cache input is not provided', async () => {
|
it('Should not enable caching if the packageManager field is missing in package.json and the cache input is not provided', async () => {
|
||||||
inputs['package-manager-cache'] = 'true';
|
inputs['package-manager-cache'] = 'true';
|
||||||
inputs['cache'] = '';
|
inputs['cache'] = ''; // No cache input is provided
|
||||||
isCacheActionAvailable.mockImplementation(() => true);
|
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
readFileSpy.mockImplementation(() =>
|
readFileSpy.mockImplementation(() =>
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
devEngines: {
|
//packageManager field is not present
|
||||||
packageManager: {name: 'npm'}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should enable caching when devEngines.packageManager is array and one entry has name "npm"', async () => {
|
|
||||||
inputs['package-manager-cache'] = 'true';
|
|
||||||
inputs['cache'] = '';
|
|
||||||
isCacheActionAvailable.mockImplementation(() => true);
|
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(() =>
|
|
||||||
JSON.stringify({
|
|
||||||
devEngines: {
|
|
||||||
packageManager: [{name: 'pnpm'}, {name: 'npm'}]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should not enable caching if packageManager is "pnpm@8.0.0" and cache input is not provided', async () => {
|
|
||||||
inputs['package-manager-cache'] = 'true';
|
|
||||||
inputs['cache'] = '';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(() =>
|
|
||||||
JSON.stringify({
|
|
||||||
packageManager: 'pnpm@8.0.0'
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(saveStateSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should not enable caching if devEngines.packageManager.name is "pnpm"', async () => {
|
|
||||||
inputs['package-manager-cache'] = 'true';
|
|
||||||
inputs['cache'] = '';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(() =>
|
|
||||||
JSON.stringify({
|
|
||||||
devEngines: {
|
|
||||||
packageManager: {name: 'pnpm'}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(saveStateSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should not enable caching if devEngines.packageManager is array without "npm"', async () => {
|
|
||||||
inputs['package-manager-cache'] = 'true';
|
|
||||||
inputs['cache'] = '';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(() =>
|
|
||||||
JSON.stringify({
|
|
||||||
devEngines: {
|
|
||||||
packageManager: [{name: 'pnpm'}, {name: 'yarn'}]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(saveStateSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should not enable caching if packageManager field is missing in package.json and cache input is not provided', async () => {
|
|
||||||
inputs['package-manager-cache'] = 'true';
|
|
||||||
inputs['cache'] = '';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
|
||||||
readFileSpy.mockImplementation(() =>
|
|
||||||
JSON.stringify({
|
|
||||||
// packageManager field is not present
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -413,18 +324,24 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
it('Should skip caching when package-manager-cache is false', async () => {
|
it('Should skip caching when package-manager-cache is false', async () => {
|
||||||
inputs['package-manager-cache'] = 'false';
|
inputs['package-manager-cache'] = 'false';
|
||||||
inputs['cache'] = '';
|
inputs['cache'] = ''; // No cache input is provided
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(saveStateSpy).not.toHaveBeenCalled();
|
expect(saveStateSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should enable caching with cache input explicitly provided', async () => {
|
it('Should enable caching with cache input explicitly provided', async () => {
|
||||||
inputs['package-manager-cache'] = 'true';
|
inputs['package-manager-cache'] = 'true';
|
||||||
inputs['cache'] = 'npm';
|
inputs['cache'] = 'npm'; // Explicit cache input provided
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
isCacheActionAvailable.mockImplementation(() => true);
|
isCacheActionAvailable.mockImplementation(() => true);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ inputs:
|
|||||||
cache:
|
cache:
|
||||||
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
|
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
|
||||||
package-manager-cache:
|
package-manager-cache:
|
||||||
description: 'Set to false to disable automatic caching. By default, caching is enabled when either devEngines.packageManager or the top-level packageManager field in package.json specifies npm as the package manager.'
|
description: 'Set to false to disable automatic caching. By default, caching is enabled when npm is the specified package manager in package.json.'
|
||||||
default: true
|
default: true
|
||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
|
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
|
||||||
|
|||||||
35
dist/setup/index.js
vendored
35
dist/setup/index.js
vendored
@@ -99786,6 +99786,7 @@ function run() {
|
|||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
const resolvedPackageManager = getNameFromPackageManagerField();
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
if ((0, cache_utils_1.isCacheFeatureAvailable)()) {
|
if ((0, cache_utils_1.isCacheFeatureAvailable)()) {
|
||||||
// if the cache input is provided, use it for caching.
|
// if the cache input is provided, use it for caching.
|
||||||
@@ -99794,14 +99795,11 @@ function run() {
|
|||||||
yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath);
|
yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath);
|
||||||
// package manager npm is detected from package.json, enable auto-caching for npm.
|
// package manager npm is detected from package.json, enable auto-caching for npm.
|
||||||
}
|
}
|
||||||
else if (packagemanagercache) {
|
else if (resolvedPackageManager && packagemanagercache) {
|
||||||
const resolvedPackageManager = getNameFromPackageManagerField();
|
core.info("Detected npm as the package manager from package.json's packageManager field. " +
|
||||||
if (resolvedPackageManager) {
|
'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false');
|
||||||
core.info("Detected npm as the package manager from package.json's packageManager field. " +
|
core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager);
|
||||||
'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false');
|
yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath);
|
||||||
core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager);
|
|
||||||
yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||||
@@ -99838,26 +99836,17 @@ function resolveVersionInput() {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
function getNameFromPackageManagerField() {
|
function getNameFromPackageManagerField() {
|
||||||
var _a;
|
// Enable auto-cache for npm
|
||||||
const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..."
|
|
||||||
try {
|
try {
|
||||||
const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8'));
|
const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8'));
|
||||||
// Check devEngines.packageManager first (object or array)
|
const pm = packageJson.packageManager;
|
||||||
const devPM = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.devEngines) === null || _a === void 0 ? void 0 : _a.packageManager;
|
if (typeof pm === 'string') {
|
||||||
const devPMArray = devPM ? (Array.isArray(devPM) ? devPM : [devPM]) : [];
|
const match = pm.match(/^(?:\^)?(npm)@/);
|
||||||
for (const obj of devPMArray) {
|
return match ? match[1] : undefined;
|
||||||
if (typeof (obj === null || obj === void 0 ? void 0 : obj.name) === 'string' && npmRegex.test(obj.name)) {
|
|
||||||
return 'npm';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check top-level packageManager
|
|
||||||
const topLevelPM = packageJson === null || packageJson === void 0 ? void 0 : packageJson.packageManager;
|
|
||||||
if (typeof topLevelPM === 'string' && npmRegex.test(topLevelPM)) {
|
|
||||||
return 'npm';
|
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
catch (_b) {
|
catch (err) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
check-latest: true
|
check-latest: true
|
||||||
@@ -64,7 +64,7 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -98,7 +98,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
||||||
@@ -119,7 +119,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0
|
node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -134,7 +134,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24
|
node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -150,7 +150,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: 'v24.0.0-v8-canary2025030537242e55ac'
|
node-version: 'v24.0.0-v8-canary2025030537242e55ac'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -170,7 +170,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24-nightly' # it will install the latest nightly release for node 24
|
node-version: '24-nightly' # it will install the latest nightly release for node 24
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -186,7 +186,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0
|
node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -202,7 +202,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.0.0-nightly202505066102159fa1'
|
node-version: '24.0.0-nightly202505066102159fa1'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -220,7 +220,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.0.0-rc.4'
|
node-version: '24.0.0-rc.4'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -238,7 +238,7 @@ Yarn caching handles both Yarn Classic (v1) and Yarn Berry (v2, v3, v4+).
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
@@ -260,7 +260,7 @@ steps:
|
|||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
cache: 'pnpm'
|
cache: 'pnpm'
|
||||||
@@ -276,7 +276,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -289,7 +289,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -320,14 +320,14 @@ jobs:
|
|||||||
- x64
|
- x64
|
||||||
# an extra windows-x86 run:
|
# an extra windows-x86 run:
|
||||||
include:
|
include:
|
||||||
- os: windows-latest
|
- os: windows-2022
|
||||||
node_version: 24
|
node_version: 24
|
||||||
architecture: x86
|
architecture: x86
|
||||||
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
|
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v6
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node_version }}
|
node-version: ${{ matrix.node_version }}
|
||||||
architecture: ${{ matrix.architecture }}
|
architecture: ${{ matrix.architecture }}
|
||||||
@@ -339,7 +339,7 @@ jobs:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '24.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
@@ -347,7 +347,7 @@ steps:
|
|||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
@@ -359,7 +359,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '24.x'
|
||||||
registry-url: <registry url>
|
registry-url: <registry url>
|
||||||
@@ -367,7 +367,7 @@ steps:
|
|||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
@@ -379,7 +379,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '24.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
@@ -399,7 +399,7 @@ Below you can find a sample "Setup .yarnrc.yml" step, that is going to allow you
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '24.x'
|
||||||
- name: Setup .yarnrc.yml
|
- name: Setup .yarnrc.yml
|
||||||
@@ -428,7 +428,7 @@ It is possible to specify a token to authenticate with the mirror using the `mir
|
|||||||
The token will be passed as a bearer token in the `Authorization` header.
|
The token will be passed as a bearer token in the `Authorization` header.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '24.x'
|
node-version: '24.x'
|
||||||
mirror: 'https://nodejs.org/dist'
|
mirror: 'https://nodejs.org/dist'
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "6.0.0",
|
"version": "5.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "6.0.0",
|
"version": "5.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.0.3",
|
"@actions/cache": "^4.0.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "6.0.0",
|
"version": "5.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup node action",
|
"description": "setup node action",
|
||||||
"main": "lib/setup-node.js",
|
"main": "lib/setup-node.js",
|
||||||
|
|||||||
41
src/main.ts
41
src/main.ts
@@ -67,6 +67,7 @@ export async function run() {
|
|||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolvedPackageManager = getNameFromPackageManagerField();
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
|
|
||||||
if (isCacheFeatureAvailable()) {
|
if (isCacheFeatureAvailable()) {
|
||||||
@@ -75,16 +76,13 @@ export async function run() {
|
|||||||
core.saveState(State.CachePackageManager, cache);
|
core.saveState(State.CachePackageManager, cache);
|
||||||
await restoreCache(cache, cacheDependencyPath);
|
await restoreCache(cache, cacheDependencyPath);
|
||||||
// package manager npm is detected from package.json, enable auto-caching for npm.
|
// package manager npm is detected from package.json, enable auto-caching for npm.
|
||||||
} else if (packagemanagercache) {
|
} else if (resolvedPackageManager && packagemanagercache) {
|
||||||
const resolvedPackageManager = getNameFromPackageManagerField();
|
core.info(
|
||||||
if (resolvedPackageManager) {
|
"Detected npm as the package manager from package.json's packageManager field. " +
|
||||||
core.info(
|
'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'
|
||||||
"Detected npm as the package manager from package.json's packageManager field. " +
|
);
|
||||||
'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'
|
core.saveState(State.CachePackageManager, resolvedPackageManager);
|
||||||
);
|
await restoreCache(resolvedPackageManager, cacheDependencyPath);
|
||||||
core.saveState(State.CachePackageManager, resolvedPackageManager);
|
|
||||||
await restoreCache(resolvedPackageManager, cacheDependencyPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +136,7 @@ function resolveVersionInput(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNameFromPackageManagerField(): string | undefined {
|
export function getNameFromPackageManagerField(): string | undefined {
|
||||||
const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..."
|
// Enable auto-cache for npm
|
||||||
try {
|
try {
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
fs.readFileSync(
|
fs.readFileSync(
|
||||||
@@ -146,24 +144,13 @@ export function getNameFromPackageManagerField(): string | undefined {
|
|||||||
'utf-8'
|
'utf-8'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
const pm = packageJson.packageManager;
|
||||||
// Check devEngines.packageManager first (object or array)
|
if (typeof pm === 'string') {
|
||||||
const devPM = packageJson?.devEngines?.packageManager;
|
const match = pm.match(/^(?:\^)?(npm)@/);
|
||||||
const devPMArray = devPM ? (Array.isArray(devPM) ? devPM : [devPM]) : [];
|
return match ? match[1] : undefined;
|
||||||
for (const obj of devPMArray) {
|
|
||||||
if (typeof obj?.name === 'string' && npmRegex.test(obj.name)) {
|
|
||||||
return 'npm';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check top-level packageManager
|
|
||||||
const topLevelPM = packageJson?.packageManager;
|
|
||||||
if (typeof topLevelPM === 'string' && npmRegex.test(topLevelPM)) {
|
|
||||||
return 'npm';
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
} catch {
|
} catch (err) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user