mirror of
https://github.com/actions/setup-node.git
synced 2026-11-17 17:49:17 +00:00
fix: exclude prereleases when resolving latest/current/node aliases (#1668)
* exclude prereleases when resolving latest/current/node aliases * test: verify stable install succeeds when skipping prereleases --------- Co-authored-by: gowridurgad <gowridurgad@gmail.com>
This commit is contained in:
1 parent
436c65619b
commit
66f83c8206
5 files changed
+136
-5
No files matched your search
@@ -270,7 +270,10 @@ jobs:
|
||||
steps:
|
||||
- name: Get node version
|
||||
run: |
|
||||
latestNodeVersion=$(curl https://nodejs.org/dist/index.json | jq -r '. [0].version')
|
||||
latestNodeVersion=$(
|
||||
curl -fsSL https://nodejs.org/dist/index.json |
|
||||
jq -r 'first(.[] | select(.version | test("-") | not) | .version)'
|
||||
)
|
||||
echo "LATEST_NODE_VERSION=$latestNodeVersion" >> $GITHUB_OUTPUT
|
||||
id: version
|
||||
shell: bash
|
||||
|
||||
@@ -151,9 +151,10 @@ Examples:
|
||||
|
||||
**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.
|
||||
|
||||
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
|
||||
`current`/`latest`/`node` always resolve to the latest stable version from [dist index](https://nodejs.org/dist/index.json) (prerelease entries are skipped).
|
||||
That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not.
|
||||
Since it will not be cached always, there is possibility of hitting rate limit when downloading from dist
|
||||
If no stable version is available in the dist index, setup fails with an explicit error.
|
||||
Since it will not always be cached, there is a possibility of hitting rate limits when downloading from dist.
|
||||
|
||||
### Checking in lockfiles
|
||||
|
||||
|
||||
@@ -993,6 +993,111 @@ describe('setup-node', () => {
|
||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
||||
}
|
||||
);
|
||||
|
||||
it.each(['latest', 'current', 'node'])(
|
||||
'skips a newer prerelease and selects the latest stable version for %s',
|
||||
async inputVersion => {
|
||||
// Arrange
|
||||
inputs['node-version'] = inputVersion;
|
||||
const stableVersion = nodeTestDist[0];
|
||||
const prereleaseVersion = {
|
||||
...nodeTestDist[0],
|
||||
version: 'v99.0.0-alpha.1'
|
||||
};
|
||||
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
|
||||
const cleanStableVersion = stableVersion.version.replace(/^v/, '');
|
||||
const toolPath = path.normalize(
|
||||
`/cache/node/${cleanStableVersion}/x64`
|
||||
);
|
||||
|
||||
findSpy.mockImplementation(() => '');
|
||||
getManifestSpy.mockImplementation(() => {
|
||||
throw new Error('Unable to download manifest');
|
||||
});
|
||||
getJsonSpy.mockImplementation((url: any) => {
|
||||
if (url === nodeVersionsManifestUrl) {
|
||||
throw new Error('Unable to download raw manifest');
|
||||
}
|
||||
|
||||
return {result: [prereleaseVersion, ...nodeTestDist]};
|
||||
});
|
||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||
exSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||
cacheSpy.mockImplementation(async () => toolPath);
|
||||
getExecOutputSpy.mockImplementation(async () => ({
|
||||
stdout: `v${cleanStableVersion}\n`,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
}));
|
||||
|
||||
// Act
|
||||
await runWithRetries();
|
||||
|
||||
// assert
|
||||
expect(findSpy).toHaveBeenCalledWith(
|
||||
'node',
|
||||
stableVersion.version,
|
||||
'x64'
|
||||
);
|
||||
expect(findSpy).not.toHaveBeenCalledWith(
|
||||
'node',
|
||||
prereleaseVersion.version,
|
||||
'x64'
|
||||
);
|
||||
expect(dlSpy).toHaveBeenCalledWith(
|
||||
`https://nodejs.org/dist/v${cleanStableVersion}/node-v${cleanStableVersion}-darwin-x64.tar.gz`,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
expect(addPathSpy).toHaveBeenCalledWith(path.join(toolPath, 'bin'));
|
||||
}
|
||||
);
|
||||
|
||||
const prereleaseOnlyIndex = [
|
||||
{...nodeTestDist[0], version: 'v99.0.0-alpha.1'}
|
||||
];
|
||||
|
||||
it.each([
|
||||
['latest', 'an empty index', []],
|
||||
['current', 'an empty index', []],
|
||||
['node', 'an empty index', []],
|
||||
['latest', 'a prerelease-only index', prereleaseOnlyIndex],
|
||||
['current', 'a prerelease-only index', prereleaseOnlyIndex],
|
||||
['node', 'a prerelease-only index', prereleaseOnlyIndex]
|
||||
])(
|
||||
'fails with the stable-version error for %s with %s',
|
||||
async (inputVersion, _description, index) => {
|
||||
// Arrange
|
||||
inputs['node-version'] = inputVersion;
|
||||
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
|
||||
findSpy.mockImplementation(() => '');
|
||||
getManifestSpy.mockImplementation(() => {
|
||||
throw new Error('Unable to download manifest');
|
||||
});
|
||||
getJsonSpy.mockImplementation((url: any) => {
|
||||
if (url === nodeVersionsManifestUrl) {
|
||||
throw new Error('Unable to download raw manifest');
|
||||
}
|
||||
|
||||
return {result: index};
|
||||
});
|
||||
|
||||
// Act
|
||||
await runWithRetries();
|
||||
|
||||
// assert
|
||||
expect(setFailedSpy).toHaveBeenCalledWith(
|
||||
`Unable to find a stable Node version for '${inputVersion}' on platform ${os.platform} and architecture ${os.arch}.`
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('latest alias syntax from cache', () => {
|
||||
@@ -1017,6 +1122,11 @@ describe('setup-node', () => {
|
||||
// assert
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
||||
expect(findSpy).toHaveBeenCalledWith(
|
||||
'node',
|
||||
expectedVersion.version,
|
||||
'x64'
|
||||
);
|
||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||
}
|
||||
);
|
||||
|
||||
Vendored
+6
-1
@@ -98991,6 +98991,7 @@ var external_node_path_default = /*#__PURE__*/__nccwpck_require__.n(external_nod
|
||||
|
||||
|
||||
|
||||
|
||||
const nodeVersionsManifestUrl = 'https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json';
|
||||
const invalidManifestMessage = 'The manifest fetched is empty, truncated, or does not contain any valid tool release entries.';
|
||||
function isValidManifest(manifest) {
|
||||
@@ -99114,7 +99115,11 @@ class OfficialBuilds extends BaseDistribution {
|
||||
let version = '';
|
||||
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
||||
core_info(`getting latest node version...`);
|
||||
return versions[0];
|
||||
const stableVersion = versions.find(potential => semver_default().prerelease(potential) === null);
|
||||
if (!stableVersion) {
|
||||
throw new Error(`Unable to find a stable Node version for '${this.nodeInfo.versionSpec}' on platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
|
||||
}
|
||||
return stableVersion;
|
||||
}
|
||||
version = super.evaluateVersions(versions);
|
||||
return version;
|
||||
|
||||
@@ -3,6 +3,7 @@ import path from 'node:path';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import semver from 'semver';
|
||||
|
||||
import BaseDistribution from '../base-distribution.js';
|
||||
import {NodeInputs, INodeVersion, INodeVersionInfo} from '../base-models.js';
|
||||
@@ -195,7 +196,18 @@ export default class OfficialBuilds extends BaseDistribution {
|
||||
|
||||
if (this.isLatestSyntax(this.nodeInfo.versionSpec)) {
|
||||
core.info(`getting latest node version...`);
|
||||
return versions[0];
|
||||
|
||||
const stableVersion = versions.find(
|
||||
potential => semver.prerelease(potential) === null
|
||||
);
|
||||
|
||||
if (!stableVersion) {
|
||||
throw new Error(
|
||||
`Unable to find a stable Node version for '${this.nodeInfo.versionSpec}' on platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
|
||||
);
|
||||
}
|
||||
|
||||
return stableVersion;
|
||||
}
|
||||
|
||||
version = super.evaluateVersions(versions);
|
||||
|
||||
Reference in new issue
Block a user