Merge branch 'actions:main' into main

This commit is contained in:
Churru14 2022-05-30 17:54:08 -05:00 committed by GitHub
commit 2f18fdc575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64540 additions and 65330 deletions

View File

@ -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...');
}
);
});
}); });

54779
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

74813
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

19
package-lock.json generated
View File

@ -23,7 +23,7 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@zeit/ncc": "^0.21.0", "@vercel/ncc": "^0.33.4",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "jest-circus": "^27.2.5",
"prettier": "^1.19.1", "prettier": "^1.19.1",
@ -1535,11 +1535,10 @@
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==", "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==",
"dev": true "dev": true
}, },
"node_modules/@zeit/ncc": { "node_modules/@vercel/ncc": {
"version": "0.21.0", "version": "0.33.4",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz", "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz",
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==", "integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==",
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
"dev": true, "dev": true,
"bin": { "bin": {
"ncc": "dist/ncc/cli.js" "ncc": "dist/ncc/cli.js"
@ -6347,10 +6346,10 @@
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==", "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==",
"dev": true "dev": true
}, },
"@zeit/ncc": { "@vercel/ncc": {
"version": "0.21.0", "version": "0.33.4",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.0.tgz", "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz",
"integrity": "sha512-RUMdvVK/w78oo+yBjruZltt0kJXYar2un/1bYQ2LuHG7GmFVm+QjxzEmySwREctaJdEnBvlMdUNWd9hXHxEI3g==", "integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==",
"dev": true "dev": true
}, },
"abab": { "abab": {

View File

@ -37,7 +37,7 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@zeit/ncc": "^0.21.0", "@vercel/ncc": "^0.33.4",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "jest-circus": "^27.2.5",
"prettier": "^1.19.1", "prettier": "^1.19.1",

View File

@ -37,6 +37,7 @@ export async function getNode(
) { ) {
// Store manifest data to avoid multiple calls // Store manifest data to avoid multiple calls
let manifest: INodeRelease[] | undefined; let manifest: INodeRelease[] | undefined;
let nodeVersions: INodeVersion[] | undefined;
let osPlat: string = os.platform(); let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch); let osArch: string = translateArchToDistUrl(arch);
@ -49,6 +50,12 @@ export async function getNode(
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); 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) { if (checkLatest) {
core.info('Attempt to resolve the latest version from manifest...'); core.info('Attempt to resolve the latest version from manifest...');
const resolvedVersion = await resolveVersionFromManifest( const resolvedVersion = await resolveVersionFromManifest(
@ -119,7 +126,7 @@ export async function getNode(
// Download from nodejs.org // Download from nodejs.org
// //
if (!downloadPath) { if (!downloadPath) {
info = await getInfoFromDist(versionSpec, arch); info = await getInfoFromDist(versionSpec, arch, nodeVersions);
if (!info) { if (!info) {
throw new Error( throw new Error(
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
@ -265,14 +272,18 @@ async function getInfoFromManifest(
async function getInfoFromDist( async function getInfoFromDist(
versionSpec: string, versionSpec: string,
arch: string = os.arch() arch: string = os.arch(),
nodeVersions?: INodeVersion[]
): Promise<INodeVersionInfo | null> { ): Promise<INodeVersionInfo | null> {
let osPlat: string = os.platform(); let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch); let osArch: string = translateArchToDistUrl(arch);
let version: string; let version: string = await queryDistForMatch(
versionSpec,
arch,
nodeVersions
);
version = await queryDistForMatch(versionSpec, arch);
if (!version) { if (!version) {
return null; return null;
} }
@ -349,7 +360,8 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
async function queryDistForMatch( async function queryDistForMatch(
versionSpec: string, versionSpec: string,
arch: string = os.arch() arch: string = os.arch(),
nodeVersions?: INodeVersion[]
): Promise<string> { ): Promise<string> {
let osPlat: string = os.platform(); let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch); let osArch: string = translateArchToDistUrl(arch);
@ -370,14 +382,14 @@ async function queryDistForMatch(
throw new Error(`Unexpected OS '${osPlat}'`); throw new Error(`Unexpected OS '${osPlat}'`);
} }
let versions: string[] = []; if (!nodeVersions) {
let nodeVersions = await getVersionsFromDist(); core.debug('No dist manifest cached');
nodeVersions = await getVersionsFromDist();
}
if ( let versions: string[] = [];
versionSpec === 'current' ||
versionSpec === 'latest' || if (isLatestSyntax(versionSpec)) {
versionSpec === 'node'
) {
core.info(`getting latest node version...`); core.info(`getting latest node version...`);
return nodeVersions[0].version; return nodeVersions[0].version;
} }
@ -482,3 +494,7 @@ export function parseNodeVersionFile(contents: string): string {
} }
return nodeVersion; return nodeVersion;
} }
function isLatestSyntax(versionSpec): boolean {
return ['current', 'latest', 'node'].includes(versionSpec);
}