3
0
Fork 0
mirror of https://gitea.com/actions/setup-node.git synced 2024-11-22 01:59:32 +01:00

Support lts/-n aliases (#481)

This commit is contained in:
Jack Bates 2022-06-02 03:30:33 -07:00 committed by GitHub
parent ed1a46e9f2
commit eeb10cff27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 309 additions and 302 deletions

View file

@ -35,13 +35,21 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] 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: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Node - name: Setup Node
uses: ./ uses: ./
with: with:
node-version: ${{ matrix.node-version }} 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: manifest:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}

View file

@ -39,7 +39,7 @@ The `node-version` input supports the following values:
- Major versions: `12`, `14`, `16` - Major versions: `12`, `14`, `16`
- More specific versions: `10.15`, `14.2.0`, `16.3.0` - 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` - 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 **Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist

View file

@ -3,50 +3,50 @@
"version": "14.0.0", "version": "14.0.0",
"stable": true, "stable": true,
"lts": "Fermium", "lts": "Fermium",
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200423.30", "release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200507.99",
"files": [ "files": [
{ {
"filename": "node-14.0.0-darwin-x64.tar.gz", "filename": "node-14.0.0-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-14.0.0-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-14.0.0-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-win32-x64.zip" "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", "version": "13.13.0",
"stable": true, "stable": true,
"release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200423.29", "release_url": "https://github.com/actions/node-versions/releases/tag/13.13.0-20200507.97",
"files": [ "files": [
{ {
"filename": "node-13.13.0-darwin-x64.tar.gz", "filename": "node-13.13.0-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-13.13.0-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-13.13.0-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200423.29/node-13.13.0-win32-x64.zip" "download_url": "https://github.com/actions/node-versions/releases/download/13.13.0-20200507.97/node-13.13.0-win32-x64.7z"
} }
] ]
}, },
@ -54,25 +54,51 @@
"version": "12.16.2", "version": "12.16.2",
"stable": true, "stable": true,
"lts": "Erbium", "lts": "Erbium",
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200423.28", "release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200507.95",
"files": [ "files": [
{ {
"filename": "node-12.16.2-darwin-x64.tar.gz", "filename": "node-12.16.2-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-12.16.2-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-12.16.2-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-win32-x64.zip" "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"
} }
] ]
}, },
@ -80,25 +106,25 @@
"version": "10.20.1", "version": "10.20.1",
"stable": true, "stable": true,
"lts": "Dubnium", "lts": "Dubnium",
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200423.27", "release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200507.70",
"files": [ "files": [
{ {
"filename": "node-10.20.1-darwin-x64.tar.gz", "filename": "node-10.20.1-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-10.20.1-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-10.20.1-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200423.27/node-10.20.1-win32-x64.zip" "download_url": "https://github.com/actions/node-versions/releases/download/10.20.1-20200507.70/node-10.20.1-win32-x64.7z"
} }
] ]
}, },
@ -106,25 +132,25 @@
"version": "8.17.0", "version": "8.17.0",
"stable": true, "stable": true,
"lts": "Carbon", "lts": "Carbon",
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200423.26", "release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200507.37",
"files": [ "files": [
{ {
"filename": "node-8.17.0-darwin-x64.tar.gz", "filename": "node-8.17.0-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-8.17.0-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-8.17.0-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200423.26/node-8.17.0-win32-x64.zip" "download_url": "https://github.com/actions/node-versions/releases/download/8.17.0-20200507.37/node-8.17.0-win32-x64.7z"
} }
] ]
}, },
@ -132,25 +158,25 @@
"version": "6.17.1", "version": "6.17.1",
"stable": true, "stable": true,
"lts": "Boron", "lts": "Boron",
"release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200423.25", "release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200529.2",
"files": [ "files": [
{ {
"filename": "node-6.17.1-darwin-x64.tar.gz", "filename": "node-6.17.1-darwin-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "darwin", "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" "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", "filename": "node-6.17.1-linux-x64.tar.gz",
"arch": "x64", "arch": "x64",
"platform": "linux", "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" "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.zip", "filename": "node-6.17.1-win32-x64.7z",
"arch": "x64", "arch": "x64",
"platform": "win32", "platform": "win32",
"download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200423.25/node-6.17.1-win32-x64.zip" "download_url": "https://github.com/actions/node-versions/releases/download/6.17.1-20200529.2/node-6.17.1-win32-x64.7z"
} }
] ]
} }

View file

@ -126,7 +126,7 @@ describe('setup-node', () => {
'mocktoken' 'mocktoken'
); );
expect(versions).toBeDefined(); expect(versions).toBeDefined();
expect(versions?.length).toBe(6); expect(versions?.length).toBe(7);
}); });
it('can mock dist versions', async () => { it('can mock dist versions', async () => {
@ -228,7 +228,7 @@ describe('setup-node', () => {
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
let expectedUrl = 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 // ... but not in the local cache
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@ -266,7 +266,7 @@ describe('setup-node', () => {
inputs['token'] = 'faketoken'; inputs['token'] = 'faketoken';
let expectedUrl = 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 // ... but not in the local cache
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@ -435,7 +435,7 @@ describe('setup-node', () => {
exSpy.mockImplementation(async () => '/some/other/temp/path'); exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
const expectedUrl = 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(); await main.run();
@ -677,11 +677,17 @@ describe('setup-node', () => {
inputs.stable = 'true'; inputs.stable = 'true';
}); });
it('find latest LTS version and resolve it from local cache (lts/erbium)', async () => { 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 // arrange
inputs['node-version'] = 'lts/erbium'; inputs['node-version'] = `lts/${lts}`;
const toolPath = path.normalize('/cache/node/12.16.2/x64'); const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
findSpy.mockReturnValue(toolPath); findSpy.mockReturnValue(toolPath);
// act // act
@ -696,28 +702,46 @@ describe('setup-node', () => {
); );
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith( expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias 'erbium' for Node version 'lts/erbium'` `LTS alias '${lts}' for Node version 'lts/${lts}'`
); );
expect(dbgSpy).toHaveBeenCalledWith( expect(dbgSpy).toHaveBeenCalledWith(
`Found LTS release '12.16.2' for Node version 'lts/erbium'` `Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'`
); );
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
expect(cnSpy).toHaveBeenCalledWith( expect(cnSpy).toHaveBeenCalledWith(
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
); );
}); }
);
it('find latest LTS version and install it from manifest (lts/erbium)', async () => { 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'
]
])(
'find latest LTS version and install it from manifest (lts/%s)',
async (lts, expectedVersion, expectedUrl) => {
// arrange // arrange
inputs['node-version'] = 'lts/erbium'; inputs['node-version'] = `lts/${lts}`;
const toolPath = path.normalize('/cache/node/12.16.2/x64'); const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`);
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path'); dlSpy.mockImplementation(async () => '/some/temp/path');
exSpy.mockImplementation(async () => '/some/other/temp/path'); exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath); cacheSpy.mockImplementation(async () => toolPath);
const expectedUrl = const expectedMajor = expectedVersion.split('.')[0];
'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz';
// act // act
await main.run(); await main.run();
@ -731,91 +755,24 @@ describe('setup-node', () => {
); );
expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached'); expect(dbgSpy).not.toHaveBeenCalledWith('No manifest cached');
expect(dbgSpy).toHaveBeenCalledWith( expect(dbgSpy).toHaveBeenCalledWith(
`LTS alias 'erbium' for Node version 'lts/erbium'` `LTS alias '${lts}' for Node version 'lts/${lts}'`
); );
expect(dbgSpy).toHaveBeenCalledWith( expect(dbgSpy).toHaveBeenCalledWith(
`Found LTS release '12.16.2' for Node version 'lts/erbium'` `Found LTS release '${expectedVersion}' for Node version 'lts/${lts}'`
); );
expect(logSpy).toHaveBeenCalledWith('Attempting to download 12...');
expect(logSpy).toHaveBeenCalledWith( expect(logSpy).toHaveBeenCalledWith(
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}` `Attempting to download ${expectedMajor}...`
);
expect(logSpy).toHaveBeenCalledWith(
`Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}`
); );
expect(logSpy).toHaveBeenCalledWith('Extracting ...'); expect(logSpy).toHaveBeenCalledWith('Extracting ...');
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
expect(cnSpy).toHaveBeenCalledWith( expect(cnSpy).toHaveBeenCalledWith(
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` `::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('fail with unable to parse LTS alias (lts/)', async () => { it('fail with unable to parse LTS alias (lts/)', async () => {
// arrange // arrange

14
dist/setup/index.js vendored
View file

@ -70756,10 +70756,18 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
throw new Error(`Unable to parse LTS alias for Node version '${versionSpec}'`); throw new Error(`Unable to parse LTS alias for Node version '${versionSpec}'`);
} }
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`); core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
// Supported formats are `lts/<alias>` and `lts/*`. Where asterisk means highest possible LTS. // Supported formats are `lts/<alias>`, `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.lts && x.stable === stable)
.map(x => [x.lts.toLowerCase(), x])
.reverse());
const numbered = Object.values(aliases);
const release = alias === '*' const release = alias === '*'
? manifest.find(x => !!x.lts && x.stable === stable) ? numbered[numbered.length - 1]
: manifest.find(x => { var _a; return ((_a = x.lts) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === alias && x.stable === stable; }); : n < 0
? numbered[numbered.length - 1 + n]
: aliases[alias];
if (!release) { if (!release) {
throw new Error(`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`); throw new Error(`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`);
} }

View file

@ -223,13 +223,21 @@ function resolveLtsAliasFromManifest(
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`); core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
// Supported formats are `lts/<alias>` and `lts/*`. Where asterisk means highest possible LTS. // Supported formats are `lts/<alias>`, `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.lts && x.stable === stable)
.map(x => [x.lts!.toLowerCase(), x])
.reverse()
);
const numbered = Object.values(aliases);
const release = const release =
alias === '*' alias === '*'
? manifest.find(x => !!x.lts && x.stable === stable) ? numbered[numbered.length - 1]
: manifest.find( : n < 0
x => x.lts?.toLowerCase() === alias && x.stable === stable ? numbered[numbered.length - 1 + n]
); : aliases[alias];
if (!release) { if (!release) {
throw new Error( throw new Error(