mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2024-12-24 11:35:48 +00:00
Logic remastered to not force check-latest
This commit is contained in:
parent
c62861c1e7
commit
92722aec8c
3 changed files with 88 additions and 53 deletions
|
@ -399,6 +399,7 @@ describe('setup-node', () => {
|
|||
expect(logSpy).not.toHaveBeenCalledWith(
|
||||
'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 () => {
|
||||
|
@ -419,6 +420,7 @@ describe('setup-node', () => {
|
|||
expect(logSpy).toHaveBeenCalledWith(
|
||||
'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(`Found in cache @ ${toolPath}`);
|
||||
});
|
||||
|
@ -443,6 +445,7 @@ describe('setup-node', () => {
|
|||
expect(logSpy).toHaveBeenCalledWith(
|
||||
'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(
|
||||
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
|
||||
|
@ -479,6 +482,7 @@ describe('setup-node', () => {
|
|||
expect(logSpy).toHaveBeenCalledWith(
|
||||
'Attempt to resolve the latest version from manifest...'
|
||||
);
|
||||
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached, getting manifest from actions/node-versions@main')
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
`Failed to resolve version ${versionSpec} from manifest`
|
||||
);
|
||||
|
@ -522,6 +526,7 @@ describe('setup-node', () => {
|
|||
);
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
'Unable to resolve version from manifest...'
|
||||
// 'Unable to get manifest...'
|
||||
);
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
`Failed to resolve version ${versionSpec} from manifest`
|
||||
|
@ -549,11 +554,11 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias 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(`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(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
|
||||
});
|
||||
|
@ -577,12 +582,12 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias 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(`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.16.2...");
|
||||
expect(logSpy).toHaveBeenCalledWith("Attempting to download 12...");
|
||||
expect(logSpy).toHaveBeenCalledWith(`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`);
|
||||
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
||||
|
@ -604,11 +609,11 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias 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(`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(cnSpy).toHaveBeenCalledWith(`::add-path::${toolPath}/bin${osm.EOL}`);
|
||||
});
|
||||
|
@ -632,12 +637,12 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias 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(`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.0.0...");
|
||||
expect(logSpy).toHaveBeenCalledWith("Attempting to download 14...");
|
||||
expect(logSpy).toHaveBeenCalledWith(`Acquiring 14.0.0 - ${os.arch} from ${expectedUrl}`);
|
||||
expect(logSpy).toHaveBeenCalledWith('Extracting ...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
||||
|
@ -658,12 +663,9 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...');
|
||||
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}`);
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
|
||||
expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::error::Unexpected LTS alias '' for Node version 'lts/'${osm.EOL}`)
|
||||
});
|
||||
|
||||
it('fail to find LTS version (lts/unknown)', async () => {
|
||||
|
@ -680,13 +682,33 @@ describe('setup-node', () => {
|
|||
await main.run();
|
||||
|
||||
// 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 the latest version from manifest...');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempt to resolve LTS alias from manifest...')
|
||||
expect(dbgSpy).toHaveBeenCalledWith('Getting manifest from actions/node-versions@main')
|
||||
expect(dbgSpy).toHaveBeenCalledWith(`LTS alias 'unknown' for Node version 'lts/unknown'`)
|
||||
expect(logSpy).toHaveBeenCalledWith('Unable to resolve version from manifest...');
|
||||
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}`);
|
||||
expect(cnSpy).toHaveBeenCalledWith(`::error::Unable to find LTS release 'unknown' for Node version 'lts/unknown'.${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
27
dist/index.js
vendored
|
@ -13105,15 +13105,20 @@ const semver = __importStar(__webpack_require__(280));
|
|||
const fs = __webpack_require__(747);
|
||||
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Store manifest data to avoid multiple calls
|
||||
let manifest;
|
||||
let osPlat = os.platform();
|
||||
let osArch = translateArchToDistUrl(arch);
|
||||
if (isLtsAlias(versionSpec)) {
|
||||
core.info('LTS version is provided. For LTS versions `check-latest` will be automatically set to true');
|
||||
checkLatest = true;
|
||||
core.info('Attempt to resolve LTS alias from manifest...');
|
||||
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) {
|
||||
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) {
|
||||
versionSpec = resolvedVersion;
|
||||
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 {
|
||||
info = yield getInfoFromManifest(versionSpec, stable, auth, osArch);
|
||||
info = yield getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
|
||||
if (info) {
|
||||
core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
|
||||
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}'`);
|
||||
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* () {
|
||||
let info = null;
|
||||
const releases = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
|
||||
if (isLtsAlias(versionSpec)) {
|
||||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, releases);
|
||||
if (!manifest) {
|
||||
core.debug('No manifest cached, getting manifest from actions/node-versions@main');
|
||||
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) {
|
||||
info = {};
|
||||
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* () {
|
||||
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;
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
@ -35,12 +35,17 @@ export async function getNode(
|
|||
auth: string | undefined,
|
||||
arch: string = os.arch()
|
||||
) {
|
||||
// Store manifest data to avoid multiple calls
|
||||
let manifest: INodeRelease[] | undefined;
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = translateArchToDistUrl(arch);
|
||||
|
||||
if (isLtsAlias(versionSpec)) {
|
||||
core.info('LTS version is provided. For LTS versions `check-latest` will be automatically set to true');
|
||||
checkLatest = true;
|
||||
core.info('Attempt to resolve LTS alias from manifest...');
|
||||
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) {
|
||||
|
@ -49,7 +54,8 @@ export async function getNode(
|
|||
versionSpec,
|
||||
stable,
|
||||
auth,
|
||||
osArch
|
||||
osArch,
|
||||
manifest
|
||||
);
|
||||
if (resolvedVersion) {
|
||||
versionSpec = resolvedVersion;
|
||||
|
@ -75,7 +81,7 @@ export async function getNode(
|
|||
// Try download from internal distribution (popular versions only)
|
||||
//
|
||||
try {
|
||||
info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
|
||||
info = await getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
|
||||
if (info) {
|
||||
core.info(
|
||||
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
|
||||
|
@ -214,21 +220,22 @@ async function getInfoFromManifest(
|
|||
versionSpec: string,
|
||||
stable: boolean,
|
||||
auth: string | undefined,
|
||||
osArch: string = translateArchToDistUrl(os.arch())
|
||||
osArch: string = translateArchToDistUrl(os.arch()),
|
||||
manifest: tc.IToolRelease[] | undefined
|
||||
): Promise<INodeVersionInfo | null> {
|
||||
let info: INodeVersionInfo | null = null;
|
||||
const releases = await tc.getManifestFromRepo(
|
||||
'actions',
|
||||
'node-versions',
|
||||
auth,
|
||||
'main'
|
||||
);
|
||||
if (!manifest) {
|
||||
core.debug('No manifest cached, getting manifest from actions/node-versions@main')
|
||||
|
||||
if (isLtsAlias(versionSpec)) {
|
||||
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, releases);
|
||||
manifest = await tc.getManifestFromRepo(
|
||||
'actions',
|
||||
'node-versions',
|
||||
auth,
|
||||
'main'
|
||||
);
|
||||
}
|
||||
|
||||
const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch);
|
||||
const rel = await tc.findFromManifest(versionSpec, stable, manifest, osArch);
|
||||
|
||||
if (rel && rel.files.length > 0) {
|
||||
info = <INodeVersionInfo>{};
|
||||
|
@ -279,10 +286,11 @@ async function resolveVersionFromManifest(
|
|||
versionSpec: string,
|
||||
stable: boolean,
|
||||
auth: string | undefined,
|
||||
osArch: string = translateArchToDistUrl(os.arch())
|
||||
osArch: string = translateArchToDistUrl(os.arch()),
|
||||
manifest: tc.IToolRelease[] | undefined
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
const info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
|
||||
const info = await getInfoFromManifest(versionSpec, stable, auth, osArch, manifest);
|
||||
return info?.resolvedVersion;
|
||||
} catch (err) {
|
||||
core.info('Unable to resolve version from manifest...');
|
||||
|
|
Loading…
Reference in a new issue