From 0ae87767634ea7afc99fbfe4722b87970be7f07a Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Mon, 2 May 2022 11:40:03 -0700 Subject: [PATCH 1/5] Support lts/-n aliases --- README.md | 2 +- __tests__/installer.test.ts | 76 +++++++++++++++++++++++++++++++++++-- dist/setup/index.js | 15 ++++++-- src/installer.ts | 19 +++++++--- 4 files changed, 100 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f920ee1ef..99a9b0e28 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The `node-version` input supports the following values: - Major versions: `12`, `14`, `16` - More specific versions: `10.15`, `14.2.0`, `16.3.0` - - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*` + - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - Latest release: `latest`/`current`/`node` **Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index f3eb8db9e..cc3c5d79f 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -77,9 +77,9 @@ describe('setup-node', () => { authSpy.mockImplementation(() => {}); // gets - getManifestSpy.mockImplementation( - () => nodeTestManifest - ); + getManifestSpy.mockImplementation(() => [ + ...(nodeTestManifest) + ]); getDistSpy.mockImplementation(() => nodeTestDist); // writes @@ -817,6 +817,76 @@ describe('setup-node', () => { ); }); + it('find latest LTS version and resolve it from local cache (lts/-2)', async () => { + // arrange + inputs['node-version'] = 'lts/-2'; + + const toolPath = path.normalize('/cache/node/12.16.2/x64'); + findSpy.mockReturnValue(toolPath); + + // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); + expect(dbgSpy).toHaveBeenCalledWith( + `LTS alias '-2' for Node version 'lts/-2'` + ); + expect(dbgSpy).toHaveBeenCalledWith( + `Found LTS release '12.16.2' for Node version 'lts/-2'` + ); + expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); + expect(cnSpy).toHaveBeenCalledWith( + `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` + ); + }); + + it('find latest LTS version and install it from manifest (lts/-2)', async () => { + // arrange + inputs['node-version'] = 'lts/-2'; + + const toolPath = path.normalize('/cache/node/12.16.2/x64'); + findSpy.mockImplementation(() => ''); + dlSpy.mockImplementation(async () => '/some/temp/path'); + exSpy.mockImplementation(async () => '/some/other/temp/path'); + cacheSpy.mockImplementation(async () => toolPath); + const expectedUrl = + 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; + + // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); + expect(dbgSpy).toHaveBeenCalledWith( + `LTS alias '-2' for Node version 'lts/-2'` + ); + expect(dbgSpy).toHaveBeenCalledWith( + `Found LTS release '12.16.2' for Node version 'lts/-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 ...'); + expect(cnSpy).toHaveBeenCalledWith( + `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` + ); + }); + it('fail with unable to parse LTS alias (lts/)', async () => { // arrange inputs['node-version'] = 'lts/'; diff --git a/dist/setup/index.js b/dist/setup/index.js index fcafff7cd..092482dc2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -70626,6 +70626,8 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info('Attempt to resolve LTS alias from manifest...'); // No try-catch since it's not possible to resolve LTS alias without manifest manifest = yield getManifest(auth); + // Reverse it so later Object.fromEntries() gets the latest version of each LTS + manifest.reverse(); versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } if (isLatestSyntax(versionSpec)) { @@ -70756,10 +70758,17 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) { throw new Error(`Unable to parse LTS alias for Node version '${versionSpec}'`); } core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`); - // Supported formats are `lts/` and `lts/*`. Where asterisk means highest possible LTS. + // Supported formats are `lts/`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest. + const n = Number(alias); + const aliases = Object.fromEntries(manifest + .filter(x => x.stable === stable) + .map(x => { var _a; return [(_a = x.lts) === null || _a === void 0 ? void 0 : _a.toLowerCase(), x]; })); + const numbered = Object.values(aliases); const release = alias === '*' - ? manifest.find(x => !!x.lts && x.stable === stable) - : manifest.find(x => { var _a; return ((_a = x.lts) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === alias && x.stable === stable; }); + ? numbered[numbered.length - 1] + : n < 0 + ? numbered[numbered.length - 1 + n] + : aliases[alias]; if (!release) { throw new Error(`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`); } diff --git a/src/installer.ts b/src/installer.ts index cd4619ea0..9ee68f862 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -46,6 +46,8 @@ export async function getNode( // No try-catch since it's not possible to resolve LTS alias without manifest manifest = await getManifest(auth); + // Reverse it so later Object.fromEntries() gets the latest version of each LTS + manifest.reverse(); versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } @@ -223,13 +225,20 @@ function resolveLtsAliasFromManifest( core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`); - // Supported formats are `lts/` and `lts/*`. Where asterisk means highest possible LTS. + // Supported formats are `lts/`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest. + const n = Number(alias); + const aliases = Object.fromEntries( + manifest + .filter(x => x.stable === stable) + .map(x => [x.lts?.toLowerCase(), x]) + ); + const numbered = Object.values(aliases); const release = alias === '*' - ? manifest.find(x => !!x.lts && x.stable === stable) - : manifest.find( - x => x.lts?.toLowerCase() === alias && x.stable === stable - ); + ? numbered[numbered.length - 1] + : n < 0 + ? numbered[numbered.length - 1 + n] + : aliases[alias]; if (!release) { throw new Error( From e884a306f8506fa3795aef8d8213e35068ea061b Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Tue, 10 May 2022 07:21:02 -0700 Subject: [PATCH 2/5] Add e2e test --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 3d8067bc9..1d349d175 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -35,7 +35,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*] + node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1] steps: - uses: actions/checkout@v3 - name: Setup Node From db5bd663432b18f1a71fc3448567a5301ae48119 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Tue, 10 May 2022 11:21:41 -0700 Subject: [PATCH 3/5] Fix e2e test --- .github/workflows/versions.yml | 8 ++++++++ __tests__/installer.test.ts | 16 ++++++++-------- dist/setup/index.js | 4 ++-- src/installer.ts | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 1d349d175..3f963491d 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -42,6 +42,14 @@ jobs: uses: ./ with: node-version: ${{ matrix.node-version }} + check-latest: true + - if: runner.os != 'Windows' + name: Verify node and npm + run: | + . "$NVM_DIR/nvm.sh" + [[ $(nvm version-remote "${{ matrix.node-version }}") =~ ^v([^.]+) ]] + __tests__/verify-node.sh "${BASH_REMATCH[1]}" + shell: bash manifest: runs-on: ${{ matrix.os }} diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index cc3c5d79f..de096e544 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -817,9 +817,9 @@ describe('setup-node', () => { ); }); - it('find latest LTS version and resolve it from local cache (lts/-2)', async () => { + it('find latest LTS version and resolve it from local cache (lts/-1)', async () => { // arrange - inputs['node-version'] = 'lts/-2'; + inputs['node-version'] = 'lts/-1'; const toolPath = path.normalize('/cache/node/12.16.2/x64'); findSpy.mockReturnValue(toolPath); @@ -836,10 +836,10 @@ describe('setup-node', () => { ); expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); expect(dbgSpy).toHaveBeenCalledWith( - `LTS alias '-2' for Node version 'lts/-2'` + `LTS alias '-1' for Node version 'lts/-1'` ); expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '12.16.2' for Node version 'lts/-2'` + `Found LTS release '12.16.2' for Node version 'lts/-1'` ); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(cnSpy).toHaveBeenCalledWith( @@ -847,9 +847,9 @@ describe('setup-node', () => { ); }); - it('find latest LTS version and install it from manifest (lts/-2)', async () => { + it('find latest LTS version and install it from manifest (lts/-1)', async () => { // arrange - inputs['node-version'] = 'lts/-2'; + inputs['node-version'] = 'lts/-1'; const toolPath = path.normalize('/cache/node/12.16.2/x64'); findSpy.mockImplementation(() => ''); @@ -871,10 +871,10 @@ describe('setup-node', () => { ); expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); expect(dbgSpy).toHaveBeenCalledWith( - `LTS alias '-2' for Node version 'lts/-2'` + `LTS alias '-1' for Node version 'lts/-1'` ); expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '12.16.2' for Node version 'lts/-2'` + `Found LTS release '12.16.2' for Node version 'lts/-1'` ); expect(logSpy).toHaveBeenCalledWith('Attempting to download 12...'); expect(logSpy).toHaveBeenCalledWith( diff --git a/dist/setup/index.js b/dist/setup/index.js index 092482dc2..e55233203 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -70761,8 +70761,8 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) { // Supported formats are `lts/`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest. const n = Number(alias); const aliases = Object.fromEntries(manifest - .filter(x => x.stable === stable) - .map(x => { var _a; return [(_a = x.lts) === null || _a === void 0 ? void 0 : _a.toLowerCase(), x]; })); + .filter(x => x.lts && x.stable === stable) + .map(x => [x.lts.toLowerCase(), x])); const numbered = Object.values(aliases); const release = alias === '*' ? numbered[numbered.length - 1] diff --git a/src/installer.ts b/src/installer.ts index 9ee68f862..92febe885 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -229,8 +229,8 @@ function resolveLtsAliasFromManifest( const n = Number(alias); const aliases = Object.fromEntries( manifest - .filter(x => x.stable === stable) - .map(x => [x.lts?.toLowerCase(), x]) + .filter(x => x.lts && x.stable === stable) + .map(x => [x.lts!.toLowerCase(), x]) ); const numbered = Object.values(aliases); const release = From c4f9da006e738880a70a0c2b9f289e4a9424db2a Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 13 May 2022 15:59:59 -0700 Subject: [PATCH 4/5] Combine LTS tests with it.each(table) --- __tests__/installer.test.ts | 295 +++++++++++------------------------- 1 file changed, 91 insertions(+), 204 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index de096e544..2a4a0282a 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -677,215 +677,102 @@ describe('setup-node', () => { inputs.stable = 'true'; }); - it('find latest LTS version and resolve it from local cache (lts/erbium)', async () => { - // arrange - inputs['node-version'] = 'lts/erbium'; - - const toolPath = path.normalize('/cache/node/12.16.2/x64'); - findSpy.mockReturnValue(toolPath); - - // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); - 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(`Found in cache @ ${toolPath}`); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); - - it('find latest LTS version and install it from manifest (lts/erbium)', async () => { - // arrange - inputs['node-version'] = 'lts/erbium'; - - const toolPath = path.normalize('/cache/node/12.16.2/x64'); - findSpy.mockImplementation(() => ''); - dlSpy.mockImplementation(async () => '/some/temp/path'); - exSpy.mockImplementation(async () => '/some/other/temp/path'); - cacheSpy.mockImplementation(async () => toolPath); - const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; - - // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); - 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('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 ...'); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); - - it('find latest LTS version and resolve it from local cache (lts/*)', async () => { - // arrange - inputs['node-version'] = 'lts/*'; - - const toolPath = path.normalize('/cache/node/14.0.0/x64'); - findSpy.mockReturnValue(toolPath); - - // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); - 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(`Found in cache @ ${toolPath}`); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); - - it('find latest LTS version and install it from manifest (lts/*)', async () => { - // arrange - inputs['node-version'] = 'lts/*'; - - const toolPath = path.normalize('/cache/node/14.0.0/x64'); - findSpy.mockImplementation(() => ''); - dlSpy.mockImplementation(async () => '/some/temp/path'); - exSpy.mockImplementation(async () => '/some/other/temp/path'); - cacheSpy.mockImplementation(async () => toolPath); - const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz'; - - // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); - 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('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 ...'); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); - - it('find latest LTS version and resolve it from local cache (lts/-1)', async () => { - // arrange - inputs['node-version'] = 'lts/-1'; - - const toolPath = path.normalize('/cache/node/12.16.2/x64'); - findSpy.mockReturnValue(toolPath); - - // act - await main.run(); + it.each([ + ['erbium', '12.16.2'], + ['*', '14.0.0'], + ['-1', '12.16.2'] + ])( + 'find latest LTS version and resolve it from local cache (lts/%s)', + async (lts, expectedVersion) => { + // arrange + inputs['node-version'] = `lts/${lts}`; + + const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); + findSpy.mockReturnValue(toolPath); - // assert - 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 '-1' for Node version 'lts/-1'` - ); - expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '12.16.2' for Node version 'lts/-1'` - ); - expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); + // act + await main.run(); - it('find latest LTS version and install it from manifest (lts/-1)', async () => { - // arrange - inputs['node-version'] = 'lts/-1'; + // assert + 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}` + ); + } + ); - const toolPath = path.normalize('/cache/node/12.16.2/x64'); - findSpy.mockImplementation(() => ''); - dlSpy.mockImplementation(async () => '/some/temp/path'); - exSpy.mockImplementation(async () => '/some/other/temp/path'); - cacheSpy.mockImplementation(async () => toolPath); - const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; + it.each([ + [ + 'erbium', + '12.16.2', + 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz' + ], + [ + '*', + '14.0.0', + 'https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz' + ], + [ + '-1', + '12.16.2', + 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz' + ] + ])( + 'find latest LTS version and install it from manifest (lts/%s)', + async (lts, expectedVersion, expectedUrl) => { + // 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(); + // 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(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); - expect(dbgSpy).toHaveBeenCalledWith( - `LTS alias '-1' for Node version 'lts/-1'` - ); - expect(dbgSpy).toHaveBeenCalledWith( - `Found LTS release '12.16.2' for Node version 'lts/-1'` - ); - 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 ...'); - expect(cnSpy).toHaveBeenCalledWith( - `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` - ); - }); + // assert + 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}` + ); + } + ); it('fail with unable to parse LTS alias (lts/)', async () => { // arrange From e8fa6b0ff52715943b021ea2b1d5d46be22bc972 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Mon, 30 May 2022 15:58:29 -0700 Subject: [PATCH 5/5] Don't reverse the manifest --- __tests__/data/versions-manifest.json | 338 ++++++++++++++------------ __tests__/installer.test.ts | 20 +- dist/setup/index.js | 5 +- src/installer.ts | 3 +- 4 files changed, 195 insertions(+), 171 deletions(-) diff --git a/__tests__/data/versions-manifest.json b/__tests__/data/versions-manifest.json index 4cf2ccee6..ee4fa7c21 100644 --- a/__tests__/data/versions-manifest.json +++ b/__tests__/data/versions-manifest.json @@ -1,157 +1,183 @@ [ - { - "version": "14.0.0", - "stable": true, - "lts": "Fermium", - "release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200423.30", - "files": [ - { - "filename": "node-14.0.0-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-darwin-x64.tar.gz" - }, - { - "filename": "node-14.0.0-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz" - }, - { - "filename": "node-14.0.0-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-win32-x64.zip" - } - ] - }, - { - "version": "13.13.0", - "stable": true, - "release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200423.29", - "files": [ - { - "filename": "node-13.13.0-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-darwin-x64.tar.gz" - }, - { - "filename": "node-13.13.0-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-linux-x64.tar.gz" - }, - { - "filename": "node-13.13.0-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-win32-x64.zip" - } - ] - }, - { - "version": "12.16.2", - "stable": true, - "lts": "Erbium", - "release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200423.28", - "files": [ - { - "filename": "node-12.16.2-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-darwin-x64.tar.gz" - }, - { - "filename": "node-12.16.2-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz" - }, - { - "filename": "node-12.16.2-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-win32-x64.zip" - } - ] - }, - { - "version": "10.20.1", - "stable": true, - "lts": "Dubnium", - "release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200423.27", - "files": [ - { - "filename": "node-10.20.1-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-darwin-x64.tar.gz" - }, - { - "filename": "node-10.20.1-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-linux-x64.tar.gz" - }, - { - "filename": "node-10.20.1-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-win32-x64.zip" - } - ] - }, - { - "version": "8.17.0", - "stable": true, - "lts": "Carbon", - "release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200423.26", - "files": [ - { - "filename": "node-8.17.0-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-darwin-x64.tar.gz" - }, - { - "filename": "node-8.17.0-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-linux-x64.tar.gz" - }, - { - "filename": "node-8.17.0-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-win32-x64.zip" - } - ] - }, - { - "version": "6.17.1", - "stable": true, - "lts": "Boron", - "release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200423.25", - "files": [ - { - "filename": "node-6.17.1-darwin-x64.tar.gz", - "arch": "x64", - "platform": "darwin", - "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-darwin-x64.tar.gz" - }, - { - "filename": "node-6.17.1-linux-x64.tar.gz", - "arch": "x64", - "platform": "linux", - "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-linux-x64.tar.gz" - }, - { - "filename": "node-6.17.1-win32-x64.zip", - "arch": "x64", - "platform": "win32", - "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-win32-x64.zip" - } - ] - } - ] \ No newline at end of file + { + "version": "14.0.0", + "stable": true, + "lts": "Fermium", + "release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200507.99", + "files": [ + { + "filename": "node-14.0.0-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-darwin-x64.tar.gz" + }, + { + "filename": "node-14.0.0-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-linux-x64.tar.gz" + }, + { + "filename": "node-14.0.0-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200507.99/node-14.0.0-win32-x64.7z" + } + ] + }, + { + "version": "13.13.0", + "stable": true, + "release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200507.97", + "files": [ + { + "filename": "node-13.13.0-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-darwin-x64.tar.gz" + }, + { + "filename": "node-13.13.0-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-linux-x64.tar.gz" + }, + { + "filename": "node-13.13.0-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-win32-x64.7z" + } + ] + }, + { + "version": "12.16.2", + "stable": true, + "lts": "Erbium", + "release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200507.95", + "files": [ + { + "filename": "node-12.16.2-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-darwin-x64.tar.gz" + }, + { + "filename": "node-12.16.2-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz" + }, + { + "filename": "node-12.16.2-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-win32-x64.7z" + } + ] + }, + { + "version": "12.0.0", + "stable": true, + "lts": "Erbium", + "release_url": "https://github.com/actions/node-versions/releases/tag/12.0.0-20200507.71", + "files": [ + { + "filename": "node-12.0.0-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-darwin-x64.tar.gz" + }, + { + "filename": "node-12.0.0-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-linux-x64.tar.gz" + }, + { + "filename": "node-12.0.0-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/12.0.0-20200507.71/node-12.0.0-win32-x64.7z" + } + ] + }, + { + "version": "10.20.1", + "stable": true, + "lts": "Dubnium", + "release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200507.70", + "files": [ + { + "filename": "node-10.20.1-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-darwin-x64.tar.gz" + }, + { + "filename": "node-10.20.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-linux-x64.tar.gz" + }, + { + "filename": "node-10.20.1-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-win32-x64.7z" + } + ] + }, + { + "version": "8.17.0", + "stable": true, + "lts": "Carbon", + "release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200507.37", + "files": [ + { + "filename": "node-8.17.0-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-darwin-x64.tar.gz" + }, + { + "filename": "node-8.17.0-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-linux-x64.tar.gz" + }, + { + "filename": "node-8.17.0-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-win32-x64.7z" + } + ] + }, + { + "version": "6.17.1", + "stable": true, + "lts": "Boron", + "release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200529.2", + "files": [ + { + "filename": "node-6.17.1-darwin-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-darwin-x64.tar.gz" + }, + { + "filename": "node-6.17.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-linux-x64.tar.gz" + }, + { + "filename": "node-6.17.1-win32-x64.7z", + "arch": "x64", + "platform": "win32", + "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-win32-x64.7z" + } + ] + } +] diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 2a4a0282a..5a3ad553f 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -77,9 +77,9 @@ describe('setup-node', () => { authSpy.mockImplementation(() => {}); // gets - getManifestSpy.mockImplementation(() => [ - ...(nodeTestManifest) - ]); + getManifestSpy.mockImplementation( + () => nodeTestManifest + ); getDistSpy.mockImplementation(() => nodeTestDist); // writes @@ -126,7 +126,7 @@ describe('setup-node', () => { 'mocktoken' ); expect(versions).toBeDefined(); - expect(versions?.length).toBe(6); + expect(versions?.length).toBe(7); }); it('can mock dist versions', async () => { @@ -228,7 +228,7 @@ describe('setup-node', () => { inputs['token'] = 'faketoken'; let expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; + '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(() => ''); @@ -266,7 +266,7 @@ describe('setup-node', () => { inputs['token'] = 'faketoken'; let expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; + '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(() => ''); @@ -435,7 +435,7 @@ describe('setup-node', () => { exSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); const expectedUrl = - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz'; + 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'; await main.run(); @@ -718,17 +718,17 @@ describe('setup-node', () => { [ 'erbium', '12.16.2', - 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz' + '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-20200423.30/node-14.0.0-linux-x64.tar.gz' + '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-20200423.28/node-12.16.2-linux-x64.tar.gz' + 'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz' ] ])( 'find latest LTS version and install it from manifest (lts/%s)', diff --git a/dist/setup/index.js b/dist/setup/index.js index e55233203..7ce48af55 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -70626,8 +70626,6 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info('Attempt to resolve LTS alias from manifest...'); // No try-catch since it's not possible to resolve LTS alias without manifest manifest = yield getManifest(auth); - // Reverse it so later Object.fromEntries() gets the latest version of each LTS - manifest.reverse(); versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } if (isLatestSyntax(versionSpec)) { @@ -70762,7 +70760,8 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) { const n = Number(alias); const aliases = Object.fromEntries(manifest .filter(x => x.lts && x.stable === stable) - .map(x => [x.lts.toLowerCase(), x])); + .map(x => [x.lts.toLowerCase(), x]) + .reverse()); const numbered = Object.values(aliases); const release = alias === '*' ? numbered[numbered.length - 1] diff --git a/src/installer.ts b/src/installer.ts index 92febe885..97e3bcaee 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -46,8 +46,6 @@ export async function getNode( // No try-catch since it's not possible to resolve LTS alias without manifest manifest = await getManifest(auth); - // Reverse it so later Object.fromEntries() gets the latest version of each LTS - manifest.reverse(); versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } @@ -231,6 +229,7 @@ function resolveLtsAliasFromManifest( manifest .filter(x => x.lts && x.stable === stable) .map(x => [x.lts!.toLowerCase(), x]) + .reverse() ); const numbered = Object.values(aliases); const release =