mirror of
https://github.com/actions/setup-node
synced 2026-11-30 21:40:35 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8cb94e61d |
@@ -151,32 +151,6 @@ jobs:
|
|||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
allow-alpha:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
node-version: [27, 27.0.0]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
- name: Setup Node with allow-alpha
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
allow-alpha: true
|
|
||||||
- name: Verify an alpha is installed
|
|
||||||
run: |
|
|
||||||
nodeVersion=$(node --version)
|
|
||||||
if [[ "$nodeVersion" != *-alpha* ]]; then
|
|
||||||
echo "Expected a Node.js alpha but found $nodeVersion. Move this job to the next alpha release line."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
- name: Verify node and npm
|
|
||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
version-file:
|
version-file:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ See [action.yml](action.yml)
|
|||||||
# Default: false
|
# Default: false
|
||||||
check-latest: false
|
check-latest: false
|
||||||
|
|
||||||
# Allow alpha releases when no stable release matches the version spec.
|
|
||||||
# Default: false
|
|
||||||
allow-alpha: false
|
|
||||||
|
|
||||||
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
||||||
# Default: ''. The action use system architecture by default
|
# Default: ''. The action use system architecture by default
|
||||||
architecture: ''
|
architecture: ''
|
||||||
@@ -259,7 +255,6 @@ If the runner is not able to access github.com, any Nodejs versions requested du
|
|||||||
## Advanced usage
|
## Advanced usage
|
||||||
|
|
||||||
- [Check latest version](docs/advanced-usage.md#check-latest-version)
|
- [Check latest version](docs/advanced-usage.md#check-latest-version)
|
||||||
- [Allow alpha releases](docs/advanced-usage.md#allow-alpha-releases)
|
|
||||||
- [Using a node version file](docs/advanced-usage.md#node-version-file)
|
- [Using a node version file](docs/advanced-usage.md#node-version-file)
|
||||||
- [Using different architectures](docs/advanced-usage.md#architecture)
|
- [Using different architectures](docs/advanced-usage.md#architecture)
|
||||||
- [Using v8 canary versions](docs/advanced-usage.md#v8-canary-versions)
|
- [Using v8 canary versions](docs/advanced-usage.md#v8-canary-versions)
|
||||||
|
|||||||
@@ -792,160 +792,6 @@ describe('setup-node', () => {
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('allow-alpha', () => {
|
|
||||||
const olderAlpha = '27.0.0-alpha.0.0.9';
|
|
||||||
const newestAlpha = '27.0.0-alpha.0.0.10';
|
|
||||||
const files = ['linux-x64'];
|
|
||||||
let releases: INodeVersion[];
|
|
||||||
|
|
||||||
function expectInstalled(version: string) {
|
|
||||||
const toolPath = path.normalize(`/cache/node/${version}/${os.arch}`);
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
getExecOutputSpy.mockImplementation(async () => ({
|
|
||||||
stdout: `v${version}`,
|
|
||||||
stderr: '',
|
|
||||||
exitCode: 0
|
|
||||||
}));
|
|
||||||
return toolPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
inputs['allow-alpha'] = 'true';
|
|
||||||
inputs['node-version'] = '27';
|
|
||||||
releases = [
|
|
||||||
{version: `v${olderAlpha}`, files},
|
|
||||||
{version: `v${newestAlpha}`, files},
|
|
||||||
{version: 'v28.0.0-alpha.0.0.0', files},
|
|
||||||
{version: 'v26.1.0', files}
|
|
||||||
];
|
|
||||||
getJsonSpy.mockImplementation(async () => ({result: releases}));
|
|
||||||
findSpy.mockReturnValue('');
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
exSpy.mockImplementation(async () => '/some/extracted/path');
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
'27',
|
|
||||||
'27.x',
|
|
||||||
'27.0',
|
|
||||||
'27.0.0',
|
|
||||||
'^27.0.0',
|
|
||||||
'~27.0.0',
|
|
||||||
'>=27.0.0 <28.0.0'
|
|
||||||
])('selects the newest matching alpha for %s', async versionSpec => {
|
|
||||||
inputs['node-version'] = versionSpec;
|
|
||||||
expectInstalled(newestAlpha);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
||||||
expect(dlSpy).toHaveBeenCalledWith(
|
|
||||||
`https://nodejs.org/dist/v${newestAlpha}/node-v${newestAlpha}-linux-x64.tar.gz`,
|
|
||||||
undefined,
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(['27', '27.0.0'])(
|
|
||||||
'prefers a stable release for %s over a newer alpha',
|
|
||||||
async versionSpec => {
|
|
||||||
inputs['node-version'] = versionSpec;
|
|
||||||
releases.push({version: 'v27.0.0', files});
|
|
||||||
expectInstalled('27.0.0');
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
||||||
expect(cacheSpy).toHaveBeenCalledWith(
|
|
||||||
'/some/extracted/path',
|
|
||||||
'node',
|
|
||||||
'27.0.0',
|
|
||||||
'x64'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each([undefined, 'false'])(
|
|
||||||
'does not select an alpha and suggests the input when allow-alpha is %s',
|
|
||||||
async allowAlpha => {
|
|
||||||
inputs['allow-alpha'] = allowAlpha;
|
|
||||||
await main.run();
|
|
||||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
|
||||||
"Unable to find Node version '27' for platform linux and architecture x64. A matching alpha release is available; set 'allow-alpha: true' to use it."
|
|
||||||
);
|
|
||||||
expect(dlSpy).not.toHaveBeenCalled();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it.each(['latest', 'current', 'node'])(
|
|
||||||
'installs the newest stable release for %s',
|
|
||||||
async versionSpec => {
|
|
||||||
inputs['node-version'] = versionSpec;
|
|
||||||
expectInstalled('26.1.0');
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
||||||
expect(cacheSpy).toHaveBeenCalledWith(
|
|
||||||
'/some/extracted/path',
|
|
||||||
'node',
|
|
||||||
'26.1.0',
|
|
||||||
'x64'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it('does not suggest allow-alpha when no alpha matches', async () => {
|
|
||||||
inputs['allow-alpha'] = 'false';
|
|
||||||
inputs['node-version'] = '29';
|
|
||||||
await main.run();
|
|
||||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
|
||||||
"Unable to find Node version '29' for platform linux and architecture x64."
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('respects an explicit prerelease lower bound', async () => {
|
|
||||||
inputs['node-version'] = '>=27.0.0-alpha.0.0.99';
|
|
||||||
await main.run();
|
|
||||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
|
||||||
"Unable to find Node version '>=27.0.0-alpha.0.0.99' for platform linux and architecture x64."
|
|
||||||
);
|
|
||||||
expect(dlSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reuses a cached alpha instead of downloading it again', async () => {
|
|
||||||
const toolPath = expectInstalled(newestAlpha);
|
|
||||||
findSpy.mockImplementation((_tool, version) =>
|
|
||||||
version === `v${newestAlpha}` ? toolPath : ''
|
|
||||||
);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
||||||
expect(dlSpy).not.toHaveBeenCalled();
|
|
||||||
expect(addPathSpy).toHaveBeenCalledWith(path.join(toolPath, 'bin'));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('downloads a newer alpha when only an older alpha is cached', async () => {
|
|
||||||
findSpy.mockImplementation((_tool, version) =>
|
|
||||||
version === `v${olderAlpha}` ? `/cache/node/${olderAlpha}/x64` : ''
|
|
||||||
);
|
|
||||||
expectInstalled(newestAlpha);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
|
||||||
expect(cacheSpy).toHaveBeenCalledWith(
|
|
||||||
'/some/extracted/path',
|
|
||||||
'node',
|
|
||||||
newestAlpha,
|
|
||||||
'x64'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('LTS version', () => {
|
describe('LTS version', () => {
|
||||||
useRetryTimers();
|
useRetryTimers();
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ inputs:
|
|||||||
check-latest:
|
check-latest:
|
||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
|
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
|
||||||
default: false
|
default: false
|
||||||
allow-alpha:
|
|
||||||
description: 'Allow alpha releases when no stable release matches the version spec.'
|
|
||||||
default: false
|
|
||||||
registry-url:
|
registry-url:
|
||||||
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.'
|
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.'
|
||||||
scope:
|
scope:
|
||||||
|
|||||||
Vendored
+7
-49
@@ -99075,7 +99075,7 @@ class OfficialBuilds extends BaseDistribution {
|
|||||||
core_info('Falling back to download directly from Node');
|
core_info('Falling back to download directly from Node');
|
||||||
}
|
}
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
toolPath = await this.downloadDirectlyFromNode(nodeJsVersions);
|
toolPath = await this.downloadDirectlyFromNode();
|
||||||
}
|
}
|
||||||
const installedDir = toolPath;
|
const installedDir = toolPath;
|
||||||
if (this.osPlat != 'win32') {
|
if (this.osPlat != 'win32') {
|
||||||
@@ -99090,24 +99090,12 @@ class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
addPath(toolPath);
|
addPath(toolPath);
|
||||||
}
|
}
|
||||||
async downloadDirectlyFromNode(nodeJsVersions) {
|
async downloadDirectlyFromNode() {
|
||||||
nodeJsVersions ??= await this.getNodeJsVersions();
|
const nodeJsVersions = await this.getNodeJsVersions();
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
if (!evaluatedVersion) {
|
if (!evaluatedVersion) {
|
||||||
let message = `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`;
|
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
|
||||||
if (!this.nodeInfo.allowAlpha && this.findAlphaVersion(versions)) {
|
|
||||||
message += ` A matching alpha release is available; set 'allow-alpha: true' to use it.`;
|
|
||||||
}
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
// The tool cache cannot match prereleases against a range such as `27`, so reuse a cached alpha here.
|
|
||||||
if (semver_default().prerelease(evaluatedVersion)) {
|
|
||||||
const cachedPath = find('node', evaluatedVersion, this.translateArchToDistUrl(this.nodeInfo.arch));
|
|
||||||
if (cachedPath) {
|
|
||||||
core_info(`Found in cache @ ${cachedPath}`);
|
|
||||||
return cachedPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
||||||
try {
|
try {
|
||||||
@@ -99124,6 +99112,7 @@ class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
evaluateVersions(versions) {
|
evaluateVersions(versions) {
|
||||||
|
let version = '';
|
||||||
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
||||||
core_info(`getting latest node version...`);
|
core_info(`getting latest node version...`);
|
||||||
const stableVersion = versions.find(potential => semver_default().prerelease(potential) === null);
|
const stableVersion = versions.find(potential => semver_default().prerelease(potential) === null);
|
||||||
@@ -99132,37 +99121,8 @@ class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
return stableVersion;
|
return stableVersion;
|
||||||
}
|
}
|
||||||
const version = super.evaluateVersions(versions);
|
version = super.evaluateVersions(versions);
|
||||||
if (version || !this.nodeInfo.allowAlpha) {
|
return version;
|
||||||
return version;
|
|
||||||
}
|
|
||||||
// Only fall back to an alpha when no stable release matches the spec.
|
|
||||||
const alphaVersion = this.findAlphaVersion(versions);
|
|
||||||
if (alphaVersion) {
|
|
||||||
core_info(`No stable release matches '${this.nodeInfo.versionSpec}', using ${alphaVersion}`);
|
|
||||||
}
|
|
||||||
return alphaVersion;
|
|
||||||
}
|
|
||||||
// Alphas are matched by their release version, so `27.0.0` or `^27.0.0` select `27.0.0-alpha.*`.
|
|
||||||
// Ranges with explicit prerelease bounds are already handled by standard semver.
|
|
||||||
findAlphaVersion(versions) {
|
|
||||||
const { range } = this.validRange(this.nodeInfo.versionSpec);
|
|
||||||
if (!semver_default().validRange(range) || this.hasPrereleaseBound(range)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return (versions.find(potential => {
|
|
||||||
const parsed = semver_default().parse(potential);
|
|
||||||
return (parsed?.prerelease[0] === 'alpha' &&
|
|
||||||
semver_default().satisfies(`${parsed.major}.${parsed.minor}.${parsed.patch}`, range));
|
|
||||||
}) ?? '');
|
|
||||||
}
|
|
||||||
hasPrereleaseBound(range) {
|
|
||||||
// semver desugars `27`, `^27.0.0`, etc. into an upper bound such as `<28.0.0-0`; ignore that synthetic `-0`.
|
|
||||||
return new (semver_default()).Range(range).set.some(comparators => comparators.some(({ operator, semver: bound }) => {
|
|
||||||
const prerelease = bound.prerelease ?? [];
|
|
||||||
const isSyntheticUpperBound = operator === '<' && prerelease.length === 1 && prerelease[0] === 0;
|
|
||||||
return prerelease.length > 0 && !isSyntheticUpperBound;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
getDistributionUrl(mirror) {
|
getDistributionUrl(mirror) {
|
||||||
const url = mirror || 'https://nodejs.org';
|
const url = mirror || 'https://nodejs.org';
|
||||||
@@ -99369,11 +99329,9 @@ async function run() {
|
|||||||
const mirrorToken = getInput('mirror-token');
|
const mirrorToken = getInput('mirror-token');
|
||||||
const stable = (getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
const stable = (getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||||
const checkLatest = (getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
const checkLatest = (getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||||
const allowAlpha = (getInput('allow-alpha') || 'false').toUpperCase() === 'TRUE';
|
|
||||||
const nodejsInfo = {
|
const nodejsInfo = {
|
||||||
versionSpec: version,
|
versionSpec: version,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
allowAlpha,
|
|
||||||
auth,
|
auth,
|
||||||
stable,
|
stable,
|
||||||
arch,
|
arch,
|
||||||
|
|||||||
@@ -74,28 +74,6 @@ steps:
|
|||||||
- run: npm test
|
- run: npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Allow alpha releases
|
|
||||||
|
|
||||||
The `allow-alpha` input defaults to `false`. Set it to `true` to use an alpha release when no stable release matches the requested version.
|
|
||||||
|
|
||||||
Alphas are matched by their release version, so `27`, `27.x`, `27.0.0`, `^27.0.0`, and `~27.0.0` all select the newest Node.js 27 alpha. Ranges with an explicit prerelease bound, such as `>=27.0.0-alpha.3`, use standard semver matching.
|
|
||||||
|
|
||||||
Alpha builds are not published for every platform. For example, Node.js 27 alphas are not available for macOS x64, so setup fails on those runners.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v7
|
|
||||||
- uses: actions/setup-node@v7
|
|
||||||
with:
|
|
||||||
node-version: '27'
|
|
||||||
allow-alpha: true
|
|
||||||
package-manager-cache: false # Disable automatic npm caching if not required
|
|
||||||
- run: npm ci
|
|
||||||
- run: npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
Exact alpha versions such as `27.0.0-alpha.0.0.0` work without `allow-alpha`.
|
|
||||||
|
|
||||||
## Node version file
|
## Node version file
|
||||||
|
|
||||||
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version`, `.tool-versions`, `mise.toml`, or `package.json`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version`, `.tool-versions`, `mise.toml`, or `package.json`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
|
||||||
|
|||||||
Generated
+3
-3
@@ -6624,9 +6624,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
"node_modules/undici": {
|
||||||
"version": "6.29.0",
|
"version": "6.29.1",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.29.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-6.29.1.tgz",
|
||||||
"integrity": "sha512-R+RODBqp6i2pPflGdq+xIOUkl+RNfGgHwoinecKu/JCuf2uO06cOKoDbI2P7Dn6KcswdKwrczbU6IYJ6K8X+wg==",
|
"integrity": "sha512-EvRlUt/QqAEvXdQeRMYUfwOQsfzpDztykrG2owGEE/rBOBoYv9uF39ZzsNDh4lTFHhTr2XOZjKkYgueD12ZmGA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.17"
|
"node": ">=18.17"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ export interface NodeInputs {
|
|||||||
arch: string;
|
arch: string;
|
||||||
auth?: string;
|
auth?: string;
|
||||||
checkLatest: boolean;
|
checkLatest: boolean;
|
||||||
allowAlpha: boolean;
|
|
||||||
stable: boolean;
|
stable: boolean;
|
||||||
mirror: string;
|
mirror: string;
|
||||||
mirrorToken: string;
|
mirrorToken: string;
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
toolPath = await this.downloadDirectlyFromNode(nodeJsVersions);
|
toolPath = await this.downloadDirectlyFromNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
const installedDir = toolPath;
|
const installedDir = toolPath;
|
||||||
@@ -162,30 +162,15 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
core.addPath(toolPath);
|
core.addPath(toolPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async downloadDirectlyFromNode(nodeJsVersions?: INodeVersion[]) {
|
protected async downloadDirectlyFromNode() {
|
||||||
nodeJsVersions ??= await this.getNodeJsVersions();
|
const nodeJsVersions = await this.getNodeJsVersions();
|
||||||
const versions = this.filterVersions(nodeJsVersions);
|
const versions = this.filterVersions(nodeJsVersions);
|
||||||
const evaluatedVersion = this.evaluateVersions(versions);
|
const evaluatedVersion = this.evaluateVersions(versions);
|
||||||
|
|
||||||
if (!evaluatedVersion) {
|
if (!evaluatedVersion) {
|
||||||
let message = `Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`;
|
throw new Error(
|
||||||
if (!this.nodeInfo.allowAlpha && this.findAlphaVersion(versions)) {
|
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
||||||
message += ` A matching alpha release is available; set 'allow-alpha: true' to use it.`;
|
|
||||||
}
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The tool cache cannot match prereleases against a range such as `27`, so reuse a cached alpha here.
|
|
||||||
if (semver.prerelease(evaluatedVersion)) {
|
|
||||||
const cachedPath = tc.find(
|
|
||||||
'node',
|
|
||||||
evaluatedVersion,
|
|
||||||
this.translateArchToDistUrl(this.nodeInfo.arch)
|
|
||||||
);
|
);
|
||||||
if (cachedPath) {
|
|
||||||
core.info(`Found in cache @ ${cachedPath}`);
|
|
||||||
return cachedPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
const toolName = this.getNodejsDistInfo(evaluatedVersion);
|
||||||
@@ -207,6 +192,8 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected evaluateVersions(versions: string[]): string {
|
protected evaluateVersions(versions: string[]): string {
|
||||||
|
let version = '';
|
||||||
|
|
||||||
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
|
|
||||||
@@ -223,54 +210,9 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||||||
return stableVersion;
|
return stableVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
const version = super.evaluateVersions(versions);
|
version = super.evaluateVersions(versions);
|
||||||
if (version || !this.nodeInfo.allowAlpha) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only fall back to an alpha when no stable release matches the spec.
|
return version;
|
||||||
const alphaVersion = this.findAlphaVersion(versions);
|
|
||||||
if (alphaVersion) {
|
|
||||||
core.info(
|
|
||||||
`No stable release matches '${this.nodeInfo.versionSpec}', using ${alphaVersion}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return alphaVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alphas are matched by their release version, so `27.0.0` or `^27.0.0` select `27.0.0-alpha.*`.
|
|
||||||
// Ranges with explicit prerelease bounds are already handled by standard semver.
|
|
||||||
private findAlphaVersion(versions: string[]): string {
|
|
||||||
const {range} = this.validRange(this.nodeInfo.versionSpec);
|
|
||||||
if (!semver.validRange(range) || this.hasPrereleaseBound(range)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
versions.find(potential => {
|
|
||||||
const parsed = semver.parse(potential);
|
|
||||||
return (
|
|
||||||
parsed?.prerelease[0] === 'alpha' &&
|
|
||||||
semver.satisfies(
|
|
||||||
`${parsed.major}.${parsed.minor}.${parsed.patch}`,
|
|
||||||
range
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}) ?? ''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private hasPrereleaseBound(range: string): boolean {
|
|
||||||
// semver desugars `27`, `^27.0.0`, etc. into an upper bound such as `<28.0.0-0`; ignore that synthetic `-0`.
|
|
||||||
return new semver.Range(range).set.some(comparators =>
|
|
||||||
comparators.some(({operator, semver: bound}) => {
|
|
||||||
const prerelease = bound.prerelease ?? [];
|
|
||||||
const isSyntheticUpperBound =
|
|
||||||
operator === '<' && prerelease.length === 1 && prerelease[0] === 0;
|
|
||||||
return prerelease.length > 0 && !isSyntheticUpperBound;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getDistributionUrl(mirror: string): string {
|
protected getDistributionUrl(mirror: string): string {
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ export async function run() {
|
|||||||
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||||
const checkLatest =
|
const checkLatest =
|
||||||
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||||
const allowAlpha =
|
|
||||||
(core.getInput('allow-alpha') || 'false').toUpperCase() === 'TRUE';
|
|
||||||
const nodejsInfo = {
|
const nodejsInfo = {
|
||||||
versionSpec: version,
|
versionSpec: version,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
allowAlpha,
|
|
||||||
auth,
|
auth,
|
||||||
stable,
|
stable,
|
||||||
arch,
|
arch,
|
||||||
|
|||||||
Reference in New Issue
Block a user