Logic remastered to not force check-latest

This commit is contained in:
Gordey Doronin 2021-06-22 15:45:25 +02:00
parent c62861c1e7
commit 92722aec8c
3 changed files with 88 additions and 53 deletions

View File

@ -399,6 +399,7 @@ describe('setup-node', () => {
expect(logSpy).not.toHaveBeenCalledWith( expect(logSpy).not.toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...' 'Attempt to resolve the latest version from manifest...'
); );
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
}); });
it('check latest version and resolve it from local cache', async () => { it('check latest version and resolve it from local cache', async () => {
@ -419,6 +420,7 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...' 'Attempt to resolve the latest version from manifest...'
); );
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'"); expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
}); });
@ -443,6 +445,7 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...' 'Attempt to resolve the latest version from manifest...'
); );
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'"); expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}` `Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
@ -479,6 +482,7 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...' 'Attempt to resolve the latest version from manifest...'
); );
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest` `Failed to resolve version ${versionSpec} from manifest`
); );
@ -522,6 +526,7 @@ describe('setup-node', () => {
); );
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
'Unable to resolve version from manifest...' 'Unable to resolve version from manifest...'
// 'Unable to get manifest...'
); );
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest` `Failed to resolve version ${versionSpec} from manifest`
@ -549,11 +554,11 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`) expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`) expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
}); });
@ -577,12 +582,12 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`) expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'erbium' for Node version 'lts/erbium'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`) expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '12.16.2' for Node version 'lts/erbium'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'"); expect(logSpy).toHaveBeenCalledWith("Attempting to download 12...");
expect(logSpy).toHaveBeenCalledWith("Attempting to download 12.16.2...");
expect(logSpy).toHaveBeenCalledWith(`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`); expect(logSpy).toHaveBeenCalledWith(`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`);
expect(logSpy).toHaveBeenCalledWith('Extracting ...'); expect(logSpy).toHaveBeenCalledWith('Extracting ...');
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
@ -604,11 +609,11 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`) expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`) expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'");
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
}); });
@ -632,12 +637,12 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`) expect(dbgSpy).toHaveBeenCalledWith(`LTS alias '*' for Node version 'lts/*'`)
expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`) expect(dbgSpy).toHaveBeenCalledWith(`Found LTS release '14.0.0' for Node version 'lts/*'`)
expect(logSpy).toHaveBeenCalledWith("Resolved as '14.0.0'"); expect(logSpy).toHaveBeenCalledWith("Attempting to download 14...");
expect(logSpy).toHaveBeenCalledWith("Attempting to download 14.0.0...");
expect(logSpy).toHaveBeenCalledWith(`Acquiring 14.0.0 - ${os.arch} from ${expectedUrl}`); expect(logSpy).toHaveBeenCalledWith(`Acquiring 14.0.0 - ${os.arch} from ${expectedUrl}`);
expect(logSpy).toHaveBeenCalledWith('Extracting ...'); expect(logSpy).toHaveBeenCalledWith('Extracting ...');
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
@ -658,12 +663,9 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...'); expect(cnSpy).toHaveBeenCalledWith(`::error::Unexpected LTS alias '' for Node version 'lts/'${osm.EOL}`)
expect(dbgSpy).toHaveBeenCalledWith(`Unexpected LTS alias '' for Node version 'lts/'`)
expect(logSpy).toHaveBeenCalledWith('Failed to resolve version lts/ from manifest');
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find Node version 'lts/' for platform linux and architecture x64.${osm.EOL}`);
}); });
it('fail to find LTS version (lts/unknown)', async () => { it('fail to find LTS version (lts/unknown)', async () => {
@ -680,13 +682,33 @@ describe('setup-node', () => {
await main.run(); await main.run();
// assert // assert
expect(logSpy).toHaveBeenCalledWith('LTS version is provided. For LTS versions `check-latest` will be automatically set to true') expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve the latest version from manifest...'); expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'unknown' for Node version 'lts/unknown'`) expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'unknown' for Node version 'lts/unknown'`)
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...'); expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find LTS release 'unknown' for Node version 'lts/unknown'.${osm.EOL}`)
expect(dbgSpy).toHaveBeenCalledWith(`Unable to find LTS release 'unknown' for Node version 'lts/unknown'.`)
expect(logSpy).toHaveBeenCalledWith('Failed to resolve version lts/unknown from manifest');
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find Node version 'lts/unknown' for platform linux and architecture x64.${osm.EOL}`);
}); });
it('fail if manifest is not available', async () => {
// arrange
os.platform = 'linux';
os.arch = 'x64';
inputs['node-version'] = 'lts/erbium';
inputs.stable = 'true';
// ... but not in the local cache
findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});
// act
await main.run();
// assert
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to download manifest${osm.EOL}`)
})
}) })
}); });

27
dist/index.js vendored
View File

@ -13105,15 +13105,20 @@ const semver = __importStar(__webpack_require__(280));
const fs = __webpack_require__(747); const fs = __webpack_require__(747);
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { 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
let manifest;
let osPlat = os.platform(); let osPlat = os.platform();
let osArch = translateArchToDistUrl(arch); let osArch = translateArchToDistUrl(arch);
if (isLtsAlias(versionSpec)) { if (isLtsAlias(versionSpec)) {
core.info('LTS version is provided. For LTS versions `check-latest` will be automatically set to true'); core.info('Attempt to resolve LTS alias from manifest...');
checkLatest = true; core.debug('Getting manifest from actions/node-versions@main');
// No try-catch since it's not possible to resolve LTS alias without manifest
manifest = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
} }
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); const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest);
if (resolvedVersion) { if (resolvedVersion) {
versionSpec = resolvedVersion; versionSpec = resolvedVersion;
core.info(`Resolved as '${versionSpec}'`); core.info(`Resolved as '${versionSpec}'`);
@ -13137,7 +13142,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
// Try download from internal distribution (popular versions only) // Try download from internal distribution (popular versions only)
// //
try { try {
info = yield getInfoFromManifest(versionSpec, stable, auth, osArch); info = yield getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
if (info) { if (info) {
core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`); core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
@ -13240,14 +13245,14 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
core.debug(`Found LTS release '${release.version}' for Node version '${versionSpec}'`); core.debug(`Found LTS release '${release.version}' for Node version '${versionSpec}'`);
return release.version.split('.')[0]; return release.version.split('.')[0];
} }
function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) { function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch()), manifest) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let info = null; let info = null;
const releases = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main'); if (!manifest) {
if (isLtsAlias(versionSpec)) { core.debug('No manifest cached, getting manifest from actions/node-versions@main');
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, releases); manifest = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
} }
const rel = yield tc.findFromManifest(versionSpec, stable, releases, osArch); const rel = yield tc.findFromManifest(versionSpec, stable, manifest, osArch);
if (rel && rel.files.length > 0) { if (rel && rel.files.length > 0) {
info = {}; info = {};
info.resolvedVersion = rel.version; info.resolvedVersion = rel.version;
@ -13284,10 +13289,10 @@ function getInfoFromDist(versionSpec, arch = os.arch()) {
}; };
}); });
} }
function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) { function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch()), manifest) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const info = yield getInfoFromManifest(versionSpec, stable, auth, osArch); const info = yield getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
return info === null || info === void 0 ? void 0 : info.resolvedVersion; return info === null || info === void 0 ? void 0 : info.resolvedVersion;
} }
catch (err) { catch (err) {

View File

@ -35,12 +35,17 @@ export async function getNode(
auth: string | undefined, auth: string | undefined,
arch: string = os.arch() arch: string = os.arch()
) { ) {
// Store manifest data to avoid multiple calls
let manifest: INodeRelease[] | undefined;
let osPlat: string = os.platform(); let osPlat: string = os.platform();
let osArch: string = translateArchToDistUrl(arch); let osArch: string = translateArchToDistUrl(arch);
if (isLtsAlias(versionSpec)) { if (isLtsAlias(versionSpec)) {
core.info('LTS version is provided. For LTS versions `check-latest` will be automatically set to true'); core.info('Attempt to resolve LTS alias from manifest...');
checkLatest = true; core.debug('Getting manifest from actions/node-versions@main')
// No try-catch since it's not possible to resolve LTS alias without manifest
manifest = await tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
} }
if (checkLatest) { if (checkLatest) {
@ -49,7 +54,8 @@ export async function getNode(
versionSpec, versionSpec,
stable, stable,
auth, auth,
osArch osArch,
manifest
); );
if (resolvedVersion) { if (resolvedVersion) {
versionSpec = resolvedVersion; versionSpec = resolvedVersion;
@ -75,7 +81,7 @@ export async function getNode(
// Try download from internal distribution (popular versions only) // Try download from internal distribution (popular versions only)
// //
try { try {
info = await getInfoFromManifest(versionSpec, stable, auth, osArch); info = await getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
if (info) { if (info) {
core.info( core.info(
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
@ -214,21 +220,22 @@ async function getInfoFromManifest(
versionSpec: string, versionSpec: string,
stable: boolean, stable: boolean,
auth: string | undefined, auth: string | undefined,
osArch: string = translateArchToDistUrl(os.arch()) osArch: string = translateArchToDistUrl(os.arch()),
manifest: tc.IToolRelease[] | undefined
): Promise<INodeVersionInfo | null> { ): Promise<INodeVersionInfo | null> {
let info: INodeVersionInfo | null = null; let info: INodeVersionInfo | null = null;
const releases = await tc.getManifestFromRepo( if (!manifest) {
core.debug('No manifest cached, getting manifest from actions/node-versions@main')
manifest = await tc.getManifestFromRepo(
'actions', 'actions',
'node-versions', 'node-versions',
auth, auth,
'main' 'main'
); );
if (isLtsAlias(versionSpec)) {
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, releases);
} }
const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch); const rel = await tc.findFromManifest(versionSpec, stable, manifest, osArch);
if (rel && rel.files.length > 0) { if (rel && rel.files.length > 0) {
info = <INodeVersionInfo>{}; info = <INodeVersionInfo>{};
@ -279,10 +286,11 @@ async function resolveVersionFromManifest(
versionSpec: string, versionSpec: string,
stable: boolean, stable: boolean,
auth: string | undefined, auth: string | undefined,
osArch: string = translateArchToDistUrl(os.arch()) osArch: string = translateArchToDistUrl(os.arch()),
manifest: tc.IToolRelease[] | undefined
): Promise<string | undefined> { ): Promise<string | undefined> {
try { try {
const info = await getInfoFromManifest(versionSpec, stable, auth, osArch); const info = await getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
return info?.resolvedVersion; return info?.resolvedVersion;
} catch (err) { } catch (err) {
core.info('Unable to resolve version from manifest...'); core.info('Unable to resolve version from manifest...');