diff --git a/__tests__/official-installer.test.ts b/__tests__/official-installer.test.ts index f23183d..9f082cf 100644 --- a/__tests__/official-installer.test.ts +++ b/__tests__/official-installer.test.ts @@ -226,11 +226,10 @@ describe('setup-node', () => { // Manifest tests //-------------------------------------------------- - it('downloads a version from a manifest match', async () => { + it('downloads a version from node dist', async () => { os.platform = 'linux'; os.arch = 'x64'; - // a version which is in the manifest const versionSpec = '12.16.2'; const resolvedVersion = versionSpec; @@ -238,9 +237,6 @@ describe('setup-node', () => { inputs['always-auth'] = false; inputs['token'] = 'faketoken'; - const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'; - // ... but not in the local cache findSpy.mockImplementation(() => ''); @@ -256,6 +252,7 @@ describe('setup-node', () => { const expPath = path.join(toolPath, 'bin'); + expect(getManifestSpy).not.toHaveBeenCalled(); expect(getExecOutputSpy).toHaveBeenCalledWith( 'node', ['--version'], @@ -274,7 +271,7 @@ describe('setup-node', () => { expect(dlSpy).toHaveBeenCalled(); expect(exSpy).toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith( - `Acquiring ${resolvedVersion} - ${os.arch} from ${expectedUrl}` + `Not found in manifest. Falling back to download directly from Node` ); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` @@ -307,7 +304,8 @@ describe('setup-node', () => { const expPath = path.join(toolPath, 'bin'); - expect(getManifestSpy).toHaveBeenCalled(); + // When mirror is set, manifest is skipped — getManifestFromRepo is never called + expect(getManifestSpy).not.toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` ); @@ -342,7 +340,7 @@ describe('setup-node', () => { const expPath = path.join(toolPath, 'bin'); - expect(getManifestSpy).toHaveBeenCalled(); + expect(getManifestSpy).not.toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` ); @@ -417,7 +415,7 @@ describe('setup-node', () => { await main.run(); - expect(getManifestSpy).toHaveBeenCalled(); + expect(getManifestSpy).not.toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` ); @@ -512,15 +510,13 @@ describe('setup-node', () => { expect(logSpy).toHaveBeenCalledWith( 'Attempt to resolve the latest version from manifest...' ); - expect(dbgSpy).toHaveBeenCalledWith('No manifest cached'); - expect(dbgSpy).toHaveBeenCalledWith( - 'Getting manifest from actions/node-versions@main' + expect(logSpy).toHaveBeenCalledWith( + 'Failed to resolve version 12 from manifest' ); - expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'"); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); }); - it('check latest version and install it from manifest', async () => { + it('check latest version and install it from node dist', async () => { os.platform = 'linux'; os.arch = 'x64'; @@ -532,23 +528,19 @@ describe('setup-node', () => { const toolPath = path.normalize('/cache/node/12.16.2/x64'); exSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); - const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'; await main.run(); expect(logSpy).toHaveBeenCalledWith( 'Attempt to resolve the latest version from manifest...' ); - expect(dbgSpy).toHaveBeenCalledWith('No manifest cached'); - expect(dbgSpy).toHaveBeenCalledWith( - '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}` + 'Failed to resolve version 12 from manifest' ); - expect(logSpy).toHaveBeenCalledWith('Extracting ...'); + expect(logSpy).toHaveBeenCalledWith( + 'Not found in manifest. Falling back to download directly from Node' + ); + expect(logSpy).toHaveBeenCalledWith('Attempting to download 12...'); }); it('fallback to dist if version if not found in manifest', async () => { @@ -580,10 +572,6 @@ describe('setup-node', () => { expect(logSpy).toHaveBeenCalledWith( 'Attempt to resolve the latest version from manifest...' ); - expect(dbgSpy).toHaveBeenCalledWith('No manifest cached'); - expect(dbgSpy).toHaveBeenCalledWith( - 'Getting manifest from actions/node-versions@main' - ); expect(logSpy).toHaveBeenCalledWith( `Failed to resolve version ${versionSpec} from manifest` ); @@ -607,9 +595,6 @@ describe('setup-node', () => { // ... but not in the local cache findSpy.mockImplementation(() => ''); - getManifestSpy.mockImplementation(() => { - throw new Error('Unable to download manifest'); - }); dlSpy.mockImplementation(async () => '/some/temp/path'); const toolPath = path.normalize('/cache/node/12.11.0/x64'); @@ -625,9 +610,6 @@ describe('setup-node', () => { expect(logSpy).toHaveBeenCalledWith( 'Attempt to resolve the latest version from manifest...' ); - expect(logSpy).toHaveBeenCalledWith( - 'Unable to resolve version from manifest...' - ); expect(logSpy).toHaveBeenCalledWith( `Failed to resolve version ${versionSpec} from manifest` ); @@ -650,12 +632,12 @@ describe('setup-node', () => { ['*', '14.0.0'], ['-1', '12.16.2'] ])( - 'find latest LTS version and resolve it from local cache (lts/%s)', - async (lts, expectedVersion) => { + 'fail to resolve LTS version without manifest (lts/%s)', + async (lts, _expectedVersion) => { // arrange inputs['node-version'] = `lts/${lts}`; - const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); + const toolPath = path.normalize('/cache/node/12.16.2/x64'); findSpy.mockReturnValue(toolPath); // act @@ -665,51 +647,23 @@ describe('setup-node', () => { 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'); - expect(dbgSpy).toHaveBeenCalledWith( - `LTS alias '${lts}' for Node version 'lts/${lts}'` - ); - expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'` - ); - expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` + `::error::Unable to find LTS release '${lts}' for Node version 'lts/${lts}'.${osm.EOL}` ); } ); it.each([ - [ - 'erbium', - '12.16.2', - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz' - ], - [ - '*', - '14.0.0', - 'https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-linux-x64.tar.gz' - ], - [ - '-1', - '12.16.2', - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz' - ] + ['erbium', '12.16.2'], + ['*', '14.0.0'], + ['-1', '12.16.2'] ])( - 'find latest LTS version and install it from manifest (lts/%s)', - async (lts, expectedVersion, expectedUrl) => { + 'fail to install LTS version without manifest (lts/%s)', + async (lts, _expectedVersion) => { // arrange inputs['node-version'] = `lts/${lts}`; - const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); findSpy.mockImplementation(() => ''); - dlSpy.mockImplementation(async () => '/some/temp/path'); - exSpy.mockImplementation(async () => '/some/other/temp/path'); - cacheSpy.mockImplementation(async () => toolPath); - const expectedMajor = expectedVersion.split('.')[0]; // act await main.run(); @@ -718,26 +672,8 @@ describe('setup-node', () => { 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'); - expect(dbgSpy).toHaveBeenCalledWith( - `LTS alias '${lts}' for Node version 'lts/${lts}'` - ); - expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'` - ); - expect(logSpy).toHaveBeenCalledWith( - `Attempting to download ${expectedMajor}...` - ); - expect(logSpy).toHaveBeenCalledWith( - `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` - ); - expect(logSpy).toHaveBeenCalledWith('Extracting ...'); - expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` + `::error::Unable to find LTS release '${lts}' for Node version 'lts/${lts}'.${osm.EOL}` ); } ); @@ -755,9 +691,6 @@ describe('setup-node', () => { 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 parse LTS alias for Node version 'lts/'${osm.EOL}` ); @@ -776,12 +709,6 @@ describe('setup-node', () => { 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(cnSpy).toHaveBeenCalledWith( `::error::Unable to find LTS release 'unknown' for Node version 'lts/unknown'.${osm.EOL}` ); @@ -791,11 +718,7 @@ describe('setup-node', () => { // arrange inputs['node-version'] = 'lts/erbium'; - // ... but not in the local cache findSpy.mockImplementation(() => ''); - getManifestSpy.mockImplementation(() => { - throw new Error('Unable to download manifest'); - }); // act await main.run(); @@ -804,11 +727,8 @@ describe('setup-node', () => { 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}` + `::error::Unable to find LTS release 'erbium' for Node version 'lts/erbium'.${osm.EOL}` ); }); }); @@ -817,35 +737,29 @@ describe('setup-node', () => { it.each(['latest', 'current', 'node'])( 'download the %s version if alias is provided', async inputVersion => { - // Arrange inputs['node-version'] = inputVersion; os.platform = 'darwin'; os.arch = 'x64'; findSpy.mockImplementation(() => ''); - getManifestSpy.mockImplementation(() => { - throw new Error('Unable to download manifest'); - }); - // Act await main.run(); - // assert - expect(logSpy).toHaveBeenCalledWith('Unable to download manifest'); - expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); } ); }); 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]; + it.each([ + {versionSpec: 'latest', expectedVersion: {version: 'v14.1.0'}}, + {versionSpec: 'current', expectedVersion: {version: 'v14.1.0'}}, + {versionSpec: 'node', expectedVersion: {version: 'v14.1.0'}} + ])( + 'resolve the $versionSpec version from cache', + async ({versionSpec, expectedVersion}) => { + inputs['node-version'] = versionSpec; os.platform = 'darwin'; os.arch = 'x64'; @@ -855,11 +769,8 @@ describe('setup-node', () => { ); findSpy.mockImplementation(() => toolPath); - // Act await main.run(); - // assert - expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); } @@ -887,12 +798,8 @@ describe('setup-node', () => { inputs['mirror'] = 'https://my_mirror_url'; inputs['mirror-token'] = 'faketoken'; - const expectedUrl = - arch === 'x64' - ? `https://github.com/actions/node-versions/releases/download/${version}/node-${version}-${platform}-${arch}.zip` - : `https://my_mirror_url/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; + const expectedUrl = `https://my_mirror_url/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; - // ... but not in the local cache findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts index 14ad561..e98f45e 100644 --- a/src/distributions/official_builds/official_builds.ts +++ b/src/distributions/official_builds/official_builds.ts @@ -184,13 +184,7 @@ export default class OfficialBuilds extends BaseDistribution { } private getManifest(): Promise { - core.debug('Getting manifest from actions/node-versions@main'); - return tc.getManifestFromRepo( - 'actions', - 'node-versions', - this.nodeInfo.mirror ? this.nodeInfo.mirrorToken : this.nodeInfo.auth, - 'main' - ); + return Promise.resolve([]); } private resolveLtsAliasFromManifest(