mirror of
https://github.com/actions/setup-node.git
synced 2024-11-13 07:01:07 +07:00
Merge branch 'actions:main' into main
This commit is contained in:
commit
2f18fdc575
@ -913,4 +913,31 @@ describe('setup-node', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('latest alias syntax from cache', () => {
|
||||
it.each(['latest', 'current', 'node'])(
|
||||
'download the %s version if alias is provided',
|
||||
async inputVersion => {
|
||||
// Arrange
|
||||
inputs['node-version'] = inputVersion;
|
||||
const expectedVersion = nodeTestDist[0];
|
||||
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
|
||||
const toolPath = path.normalize(
|
||||
`/cache/node/${expectedVersion.version}/x64`
|
||||
);
|
||||
findSpy.mockReturnValue(toolPath);
|
||||
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
// assert
|
||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith('getting latest node version...');
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
55103
dist/cache-save/index.js
vendored
55103
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
74679
dist/setup/index.js
vendored
74679
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
19
package-lock.json
generated
19
package-lock.json
generated
@ -23,7 +23,7 @@
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.25",
|
||||
"@types/semver": "^6.0.0",
|
||||
"@zeit/ncc": "^0.21.0",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.5",
|
||||
"prettier": "^1.19.1",
|
||||
@ -1535,11 +1535,10 @@
|
||||
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@zeit/ncc": {
|
||||
"version": "0.21.0",
|
||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz",
|
||||
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==",
|
||||
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
|
||||
"node_modules/@vercel/ncc": {
|
||||
"version": "0.33.4",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz",
|
||||
"integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"ncc": "dist/ncc/cli.js"
|
||||
@ -6347,10 +6346,10 @@
|
||||
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==",
|
||||
"dev": true
|
||||
},
|
||||
"@zeit/ncc": {
|
||||
"version": "0.21.0",
|
||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz",
|
||||
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==",
|
||||
"@vercel/ncc": {
|
||||
"version": "0.33.4",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz",
|
||||
"integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==",
|
||||
"dev": true
|
||||
},
|
||||
"abab": {
|
||||
|
@ -37,7 +37,7 @@
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.25",
|
||||
"@types/semver": "^6.0.0",
|
||||
"@zeit/ncc": "^0.21.0",
|
||||
"@vercel/ncc": "^0.33.4",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.5",
|
||||
"prettier": "^1.19.1",
|
||||
|
@ -37,6 +37,7 @@ export async function getNode(
|
||||
) {
|
||||
// Store manifest data to avoid multiple calls
|
||||
let manifest: INodeRelease[] | undefined;
|
||||
let nodeVersions: INodeVersion[] | undefined;
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = translateArchToDistUrl(arch);
|
||||
|
||||
@ -49,6 +50,12 @@ export async function getNode(
|
||||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
||||
}
|
||||
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
nodeVersions = await getVersionsFromDist();
|
||||
versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions);
|
||||
core.info(`getting latest node version...`);
|
||||
}
|
||||
|
||||
if (checkLatest) {
|
||||
core.info('Attempt to resolve the latest version from manifest...');
|
||||
const resolvedVersion = await resolveVersionFromManifest(
|
||||
@ -119,7 +126,7 @@ export async function getNode(
|
||||
// Download from nodejs.org
|
||||
//
|
||||
if (!downloadPath) {
|
||||
info = await getInfoFromDist(versionSpec, arch);
|
||||
info = await getInfoFromDist(versionSpec, arch, nodeVersions);
|
||||
if (!info) {
|
||||
throw new Error(
|
||||
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
||||
@ -265,14 +272,18 @@ async function getInfoFromManifest(
|
||||
|
||||
async function getInfoFromDist(
|
||||
versionSpec: string,
|
||||
arch: string = os.arch()
|
||||
arch: string = os.arch(),
|
||||
nodeVersions?: INodeVersion[]
|
||||
): Promise<INodeVersionInfo | null> {
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = translateArchToDistUrl(arch);
|
||||
|
||||
let version: string;
|
||||
let version: string = await queryDistForMatch(
|
||||
versionSpec,
|
||||
arch,
|
||||
nodeVersions
|
||||
);
|
||||
|
||||
version = await queryDistForMatch(versionSpec, arch);
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
@ -349,7 +360,8 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
|
||||
|
||||
async function queryDistForMatch(
|
||||
versionSpec: string,
|
||||
arch: string = os.arch()
|
||||
arch: string = os.arch(),
|
||||
nodeVersions?: INodeVersion[]
|
||||
): Promise<string> {
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = translateArchToDistUrl(arch);
|
||||
@ -370,14 +382,14 @@ async function queryDistForMatch(
|
||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||
}
|
||||
|
||||
let versions: string[] = [];
|
||||
let nodeVersions = await getVersionsFromDist();
|
||||
if (!nodeVersions) {
|
||||
core.debug('No dist manifest cached');
|
||||
nodeVersions = await getVersionsFromDist();
|
||||
}
|
||||
|
||||
if (
|
||||
versionSpec === 'current' ||
|
||||
versionSpec === 'latest' ||
|
||||
versionSpec === 'node'
|
||||
) {
|
||||
let versions: string[] = [];
|
||||
|
||||
if (isLatestSyntax(versionSpec)) {
|
||||
core.info(`getting latest node version...`);
|
||||
return nodeVersions[0].version;
|
||||
}
|
||||
@ -482,3 +494,7 @@ export function parseNodeVersionFile(contents: string): string {
|
||||
}
|
||||
return nodeVersion;
|
||||
}
|
||||
|
||||
function isLatestSyntax(versionSpec): boolean {
|
||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user