mirror of
https://github.com/actions/setup-node.git
synced 2026-03-01 06:41:05 +08:00
Compare commits
4 Commits
e2753a1033
...
489a1e3de5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
489a1e3de5 | ||
|
|
774c1d6296 | ||
|
|
efcb663fc6 | ||
|
|
4c2c359ddf |
13
.github/workflows/e2e-cache.yml
vendored
13
.github/workflows/e2e-cache.yml
vendored
@ -10,11 +10,15 @@ on:
|
||||
- releases/*
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
node-npm-depencies-caching:
|
||||
name: Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -38,6 +42,7 @@ jobs:
|
||||
node-pnpm-depencies-caching:
|
||||
name: Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -71,6 +76,7 @@ jobs:
|
||||
node-yarn1-depencies-caching:
|
||||
name: Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -101,6 +107,7 @@ jobs:
|
||||
node-yarn3-depencies-caching:
|
||||
name: Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
env:
|
||||
YARN_ENABLE_IMMUTABLE_INSTALLS: false
|
||||
strategy:
|
||||
@ -141,6 +148,7 @@ jobs:
|
||||
matrix:
|
||||
node-version: [20, 22, 24]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
@ -168,6 +176,7 @@ jobs:
|
||||
matrix:
|
||||
node-version: [20, 22, 24]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
@ -195,6 +204,7 @@ jobs:
|
||||
matrix:
|
||||
node-version: [20, 22, 24]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
@ -222,6 +232,7 @@ jobs:
|
||||
matrix:
|
||||
node-version: [20, 22, 24]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
@ -247,6 +258,7 @@ jobs:
|
||||
node-npm-packageManager-auto-cache:
|
||||
name: Test auto cache with top-level packageManager
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -272,6 +284,7 @@ jobs:
|
||||
node-npm-devEngines-auto-cache:
|
||||
name: Test auto cache with devEngines.packageManager
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
|
||||
15
.github/workflows/versions.yml
vendored
15
.github/workflows/versions.yml
vendored
@ -168,6 +168,21 @@ jobs:
|
||||
- name: Verify node
|
||||
run: __tests__/verify-node.sh 24
|
||||
|
||||
version-file-dev-engines:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Setup node from node version file
|
||||
uses: ./
|
||||
with:
|
||||
node-version-file: '__tests__/data/package-dev-engines.json'
|
||||
- name: Verify node
|
||||
run: __tests__/verify-node.sh 20
|
||||
|
||||
version-file-volta:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
||||
11
__tests__/data/package-dev-engines.json
Normal file
11
__tests__/data/package-dev-engines.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"engines": {
|
||||
"node": "^19"
|
||||
},
|
||||
"devEngines": {
|
||||
"runtime": {
|
||||
"name": "node",
|
||||
"version": "^20"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,22 +94,24 @@ describe('main tests', () => {
|
||||
|
||||
describe('getNodeVersionFromFile', () => {
|
||||
each`
|
||||
contents | expected
|
||||
${'12'} | ${'12'}
|
||||
${'12.3'} | ${'12.3'}
|
||||
${'12.3.4'} | ${'12.3.4'}
|
||||
${'v12.3.4'} | ${'12.3.4'}
|
||||
${'lts/erbium'} | ${'lts/erbium'}
|
||||
${'lts/*'} | ${'lts/*'}
|
||||
${'nodejs 12.3.4'} | ${'12.3.4'}
|
||||
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
|
||||
${''} | ${''}
|
||||
${'unknown format'} | ${'unknown format'}
|
||||
${' 14.1.0 '} | ${'14.1.0'}
|
||||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
||||
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
|
||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
||||
${'{}'} | ${null}
|
||||
contents | expected
|
||||
${'12'} | ${'12'}
|
||||
${'12.3'} | ${'12.3'}
|
||||
${'12.3.4'} | ${'12.3.4'}
|
||||
${'v12.3.4'} | ${'12.3.4'}
|
||||
${'lts/erbium'} | ${'lts/erbium'}
|
||||
${'lts/*'} | ${'lts/*'}
|
||||
${'nodejs 12.3.4'} | ${'12.3.4'}
|
||||
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
|
||||
${''} | ${''}
|
||||
${'unknown format'} | ${'unknown format'}
|
||||
${' 14.1.0 '} | ${'14.1.0'}
|
||||
${'{}'} | ${null}
|
||||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'} | ${'>=14.0.0 <=17.0.0'}
|
||||
${'{"volta": {"extends": "./package.json"}}'} | ${'18.0.0'}
|
||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
||||
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'}
|
||||
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'}
|
||||
`.it('parses "$contents"', ({contents, expected}) => {
|
||||
const existsSpy = jest.spyOn(fs, 'existsSync');
|
||||
existsSpy.mockImplementation(() => true);
|
||||
|
||||
11
dist/cache-save/index.js
vendored
11
dist/cache-save/index.js
vendored
@ -71877,6 +71877,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
||||
if (manifest.volta?.node) {
|
||||
return manifest.volta.node;
|
||||
}
|
||||
// support devEngines from npm 11
|
||||
if (manifest.devEngines?.runtime) {
|
||||
// find an entry with name set to node and having set a version.
|
||||
// the devEngines.runtime can either be an object or an array of objects
|
||||
const nodeEntry = [manifest.devEngines.runtime]
|
||||
.flat()
|
||||
.find(({ name, version }) => name?.toLowerCase() === 'node' && version);
|
||||
if (nodeEntry) {
|
||||
return nodeEntry.version;
|
||||
}
|
||||
}
|
||||
if (manifest.engines?.node) {
|
||||
return manifest.engines.node;
|
||||
}
|
||||
|
||||
13
dist/setup/index.js
vendored
13
dist/setup/index.js
vendored
@ -81660,7 +81660,7 @@ class BaseDistribution {
|
||||
const dataUrl = `${initialUrl}/index.json`;
|
||||
const headers = {};
|
||||
if (this.nodeInfo.mirrorToken) {
|
||||
headers['Authorization'] = `Bearer ${this.nodeInfo.mirrorToken}`;
|
||||
headers['Authorization'] = this.nodeInfo.mirrorToken;
|
||||
}
|
||||
const response = await this.httpClient.getJson(dataUrl, headers);
|
||||
return response.result || [];
|
||||
@ -82415,6 +82415,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
||||
if (manifest.volta?.node) {
|
||||
return manifest.volta.node;
|
||||
}
|
||||
// support devEngines from npm 11
|
||||
if (manifest.devEngines?.runtime) {
|
||||
// find an entry with name set to node and having set a version.
|
||||
// the devEngines.runtime can either be an object or an array of objects
|
||||
const nodeEntry = [manifest.devEngines.runtime]
|
||||
.flat()
|
||||
.find(({ name, version }) => name?.toLowerCase() === 'node' && version);
|
||||
if (nodeEntry) {
|
||||
return nodeEntry.version;
|
||||
}
|
||||
}
|
||||
if (manifest.engines?.node) {
|
||||
return manifest.engines.node;
|
||||
}
|
||||
|
||||
@ -90,21 +90,31 @@ steps:
|
||||
- run: npm test
|
||||
```
|
||||
|
||||
When using the `package.json` input, the action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`.
|
||||
When using the `package.json` input, the action will look in the following fields for a specified Node version:
|
||||
1. It checks `volta.node` first.
|
||||
2. Then it checks `devEngines.runtime` for an entry with `"name": "node"`.
|
||||
3. Then it will look for `engines.node`.
|
||||
4. Otherwise it tries to resolve the file defined by [`volta.extends`](https://docs.volta.sh/advanced/workspaces)
|
||||
and look for `volta.node`, `devEngines.runtime`, or `engines.node` recursively.
|
||||
|
||||
|
||||
```json
|
||||
{
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
"node": "^22 || ^24"
|
||||
},
|
||||
"devEngines": {
|
||||
"runtime": {
|
||||
"name": "node",
|
||||
"version": "^24.3"
|
||||
}
|
||||
},
|
||||
"volta": {
|
||||
"node": "16.0.0"
|
||||
"node": "24.11.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Otherwise, when [`volta.extends`](https://docs.volta.sh/advanced/workspaces) is defined, then it will resolve the corresponding file and look for `volta.node` or `engines.node` recursively.
|
||||
|
||||
## Architecture
|
||||
|
||||
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
||||
@ -470,7 +480,7 @@ Please refer to the [Ensuring workflow access to your package - Configuring a pa
|
||||
It is possible to use a private mirror hosting Node.js binaries. This mirror must be a full mirror of the official Node.js distribution.
|
||||
The mirror URL can be set using the `mirror` input.
|
||||
It is possible to specify a token to authenticate with the mirror using the `mirror-token` input.
|
||||
The token will be passed as a bearer token in the `Authorization` header.
|
||||
The token will be passed in the `Authorization` header.
|
||||
|
||||
```yaml
|
||||
- uses: actions/setup-node@v6
|
||||
|
||||
@ -103,7 +103,7 @@ export default abstract class BaseDistribution {
|
||||
const headers = {};
|
||||
|
||||
if (this.nodeInfo.mirrorToken) {
|
||||
headers['Authorization'] = `Bearer ${this.nodeInfo.mirrorToken}`;
|
||||
headers['Authorization'] = this.nodeInfo.mirrorToken;
|
||||
}
|
||||
|
||||
const response = await this.httpClient.getJson<INodeVersion[]>(
|
||||
|
||||
12
src/util.ts
12
src/util.ts
@ -26,6 +26,18 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||
return manifest.volta.node;
|
||||
}
|
||||
|
||||
// support devEngines from npm 11
|
||||
if (manifest.devEngines?.runtime) {
|
||||
// find an entry with name set to node and having set a version.
|
||||
// the devEngines.runtime can either be an object or an array of objects
|
||||
const nodeEntry = [manifest.devEngines.runtime]
|
||||
.flat()
|
||||
.find(({name, version}) => name?.toLowerCase() === 'node' && version);
|
||||
if (nodeEntry) {
|
||||
return nodeEntry.version;
|
||||
}
|
||||
}
|
||||
|
||||
if (manifest.engines?.node) {
|
||||
return manifest.engines.node;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user