Reuse manifest code

pull/270/head
Gordey Doronin 2021-06-22 17:52:06 +02:00
parent d9ce83b637
commit c2dfe2df98
3 changed files with 29 additions and 37 deletions

View File

@ -399,8 +399,9 @@ describe('setup-node', () => {
expect(logSpy).not.toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).not.toHaveBeenCalledWith(
'No manifest cached, getting manifest from actions/node-versions@main'
'Getting manifest from actions/node-versions@main'
);
});
@ -422,8 +423,9 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
'No manifest cached, getting manifest from actions/node-versions@main'
'Getting manifest from actions/node-versions@main'
);
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
@ -449,8 +451,9 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
'No manifest cached, getting manifest from actions/node-versions@main'
'Getting manifest from actions/node-versions@main'
);
expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(
@ -488,8 +491,9 @@ describe('setup-node', () => {
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(dbgSpy).toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
'No manifest cached, getting manifest from actions/node-versions@main'
'Getting manifest from actions/node-versions@main'
);
expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest`
@ -567,9 +571,7 @@ describe('setup-node', () => {
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).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias 'erbium' for Node version 'lts/erbium'`
);
@ -608,9 +610,7 @@ describe('setup-node', () => {
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).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias 'erbium' for Node version 'lts/erbium'`
);
@ -649,9 +649,7 @@ describe('setup-node', () => {
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).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias '*' for Node version 'lts/*'`
);
@ -690,9 +688,7 @@ describe('setup-node', () => {
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).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias '*' for Node version 'lts/*'`
);

11
dist/index.js vendored
View File

@ -13111,9 +13111,8 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
let osArch = translateArchToDistUrl(arch);
if (isLtsAlias(versionSpec)) {
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');
manifest = yield getManifest(auth);
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}
if (checkLatest) {
@ -13228,6 +13227,10 @@ exports.getNode = getNode;
function isLtsAlias(versionSpec) {
return versionSpec.startsWith('lts');
}
function getManifest(auth) {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
}
function resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
var _a;
const alias = (_a = versionSpec.split('lts/')[1]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
@ -13249,8 +13252,8 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo
return __awaiter(this, void 0, void 0, function* () {
let info = null;
if (!manifest) {
core.debug('No manifest cached, getting manifest from actions/node-versions@main');
manifest = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
core.debug('No manifest cached');
manifest = yield getManifest(auth);
}
const rel = yield tc.findFromManifest(versionSpec, stable, manifest, osArch);
if (rel && rel.files.length > 0) {

View File

@ -42,14 +42,10 @@ export async function getNode(
if (isLtsAlias(versionSpec)) {
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'
);
manifest = await getManifest(auth);
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}
@ -200,6 +196,11 @@ function isLtsAlias(versionSpec: string): boolean {
return versionSpec.startsWith('lts');
}
function getManifest(auth: string | undefined): Promise<tc.IToolRelease[]> {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
}
function resolveLtsAliasFromManifest(
versionSpec: string,
stable: boolean,
@ -245,16 +246,8 @@ async function getInfoFromManifest(
): Promise<INodeVersionInfo | null> {
let info: INodeVersionInfo | null = null;
if (!manifest) {
core.debug(
'No manifest cached, getting manifest from actions/node-versions@main'
);
manifest = await tc.getManifestFromRepo(
'actions',
'node-versions',
auth,
'main'
);
core.debug('No manifest cached');
manifest = await getManifest(auth);
}
const rel = await tc.findFromManifest(versionSpec, stable, manifest, osArch);