mirror of
https://github.com/actions/setup-node.git
synced 2024-12-23 09:29:49 +08:00
Merge pull request #496 from panticmilos/v-mpantic/get-latest-version-from-cache
Get latest version from cache if exists
This commit is contained in:
commit
daff393d43
|
@ -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...');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
27
dist/setup/index.js
vendored
27
dist/setup/index.js
vendored
|
@ -62343,6 +62343,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Store manifest data to avoid multiple calls
|
// Store manifest data to avoid multiple calls
|
||||||
let manifest;
|
let manifest;
|
||||||
|
let nodeVersions;
|
||||||
let osPlat = os.platform();
|
let osPlat = os.platform();
|
||||||
let osArch = translateArchToDistUrl(arch);
|
let osArch = translateArchToDistUrl(arch);
|
||||||
if (isLtsAlias(versionSpec)) {
|
if (isLtsAlias(versionSpec)) {
|
||||||
|
@ -62351,6 +62352,11 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||||
manifest = yield getManifest(auth);
|
manifest = yield getManifest(auth);
|
||||||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
|
||||||
}
|
}
|
||||||
|
if (isLatestSyntax(versionSpec)) {
|
||||||
|
nodeVersions = yield getVersionsFromDist();
|
||||||
|
versionSpec = yield 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 = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
|
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
|
||||||
|
@ -62402,7 +62408,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||||
// Download from nodejs.org
|
// Download from nodejs.org
|
||||||
//
|
//
|
||||||
if (!downloadPath) {
|
if (!downloadPath) {
|
||||||
info = yield getInfoFromDist(versionSpec, arch);
|
info = yield getInfoFromDist(versionSpec, arch, nodeVersions);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
|
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
|
||||||
}
|
}
|
||||||
|
@ -62502,12 +62508,11 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo
|
||||||
return info;
|
return info;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getInfoFromDist(versionSpec, arch = os.arch()) {
|
function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let osPlat = os.platform();
|
let osPlat = os.platform();
|
||||||
let osArch = translateArchToDistUrl(arch);
|
let osArch = translateArchToDistUrl(arch);
|
||||||
let version;
|
let version = yield queryDistForMatch(versionSpec, arch, nodeVersions);
|
||||||
version = yield queryDistForMatch(versionSpec, arch);
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -62566,7 +62571,7 @@ function evaluateVersions(versions, versionSpec) {
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
function queryDistForMatch(versionSpec, arch = os.arch()) {
|
function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let osPlat = os.platform();
|
let osPlat = os.platform();
|
||||||
let osArch = translateArchToDistUrl(arch);
|
let osArch = translateArchToDistUrl(arch);
|
||||||
|
@ -62585,11 +62590,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) {
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`);
|
throw new Error(`Unexpected OS '${osPlat}'`);
|
||||||
}
|
}
|
||||||
|
if (!nodeVersions) {
|
||||||
|
core.debug('No dist manifest cached');
|
||||||
|
nodeVersions = yield getVersionsFromDist();
|
||||||
|
}
|
||||||
let versions = [];
|
let versions = [];
|
||||||
let nodeVersions = yield getVersionsFromDist();
|
if (isLatestSyntax(versionSpec)) {
|
||||||
if (versionSpec === 'current' ||
|
|
||||||
versionSpec === 'latest' ||
|
|
||||||
versionSpec === 'node') {
|
|
||||||
core.info(`getting latest node version...`);
|
core.info(`getting latest node version...`);
|
||||||
return nodeVersions[0].version;
|
return nodeVersions[0].version;
|
||||||
}
|
}
|
||||||
|
@ -62688,6 +62694,9 @@ function parseNodeVersionFile(contents) {
|
||||||
return nodeVersion;
|
return nodeVersion;
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||||
|
function isLatestSyntax(versionSpec) {
|
||||||
|
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user