From c2dfe2df9884bf1033e0ee352d86309105ea6cf0 Mon Sep 17 00:00:00 2001 From: Gordey Doronin Date: Tue, 22 Jun 2021 17:52:06 +0200 Subject: [PATCH] Reuse manifest code --- __tests__/installer.test.ts | 28 ++++++++++++---------------- dist/index.js | 11 +++++++---- src/installer.ts | 27 ++++++++++----------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 2fc88d63..a6907c4c 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -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/*'` ); diff --git a/dist/index.js b/dist/index.js index a1f7f053..170f8279 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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) { diff --git a/src/installer.ts b/src/installer.ts index 2001f4d7..47d24c93 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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 { + 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 { 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);