Skip to content

Commit

Permalink
Merge pull request #270 from gordey4doronin/gordey/support-lts-syntax
Browse files Browse the repository at this point in the history
Support LTS aliases
  • Loading branch information
maxim-lobanov authored Jun 30, 2021
2 parents e79375d + 4804262 commit bcb4cec
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 19 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ jobs:
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash

lts-syntax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*]
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: ./
with:
node-version: ${{ matrix.node-version }}

manifest:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
5 changes: 5 additions & 0 deletions __tests__/data/versions-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"version": "14.0.0",
"stable": true,
"lts": "Fermium",
"release_url": "https://github.com/actions/node-versions/releases/tag/14.0.0-20200423.30",
"files": [
{
Expand Down Expand Up @@ -52,6 +53,7 @@
{
"version": "12.16.2",
"stable": true,
"lts": "Erbium",
"release_url": "https://github.com/actions/node-versions/releases/tag/12.16.2-20200423.28",
"files": [
{
Expand All @@ -77,6 +79,7 @@
{
"version": "10.20.1",
"stable": true,
"lts": "Dubnium",
"release_url": "https://github.com/actions/node-versions/releases/tag/10.20.1-20200423.27",
"files": [
{
Expand All @@ -102,6 +105,7 @@
{
"version": "8.17.0",
"stable": true,
"lts": "Carbon",
"release_url": "https://github.com/actions/node-versions/releases/tag/8.17.0-20200423.26",
"files": [
{
Expand All @@ -127,6 +131,7 @@
{
"version": "6.17.1",
"stable": true,
"lts": "Boron",
"release_url": "https://github.com/actions/node-versions/releases/tag/6.17.1-20200423.25",
"files": [
{
Expand Down
241 changes: 241 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ describe('setup-node', () => {
let match = await tc.findFromManifest('12.16.2', true, versions);
expect(match).toBeDefined();
expect(match?.version).toBe('12.16.2');
expect((match as any).lts).toBe('Erbium');
});

it('can find 12 from manifest on linux', async () => {
Expand All @@ -148,6 +149,7 @@ describe('setup-node', () => {
let match = await tc.findFromManifest('12.16.2', true, versions);
expect(match).toBeDefined();
expect(match?.version).toBe('12.16.2');
expect((match as any).lts).toBe('Erbium');
});

it('can find 10 from manifest on windows', async () => {
Expand All @@ -162,6 +164,7 @@ describe('setup-node', () => {
let match = await tc.findFromManifest('10', true, versions);
expect(match).toBeDefined();
expect(match?.version).toBe('10.20.1');
expect((match as any).lts).toBe('Dubnium');
});

//--------------------------------------------------
Expand Down Expand Up @@ -217,6 +220,10 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL);
});

//--------------------------------------------------
// Manifest tests
//--------------------------------------------------

it('downloads a version from a manifest match', async () => {
os.platform = 'linux';
os.arch = 'x64';
Expand Down Expand Up @@ -392,6 +399,10 @@ 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(
'Getting manifest from actions/node-versions@main'
);
});

it('check latest version and resolve it from local cache', async () => {
Expand All @@ -412,6 +423,10 @@ 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("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});
Expand All @@ -436,6 +451,10 @@ 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("Resolved as '12.16.2'");
expect(logSpy).toHaveBeenCalledWith(
`Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
Expand Down Expand Up @@ -472,6 +491,10 @@ 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`
);
Expand Down Expand Up @@ -525,4 +548,222 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
});

describe('LTS version', () => {
beforeEach(() => {
os.platform = 'linux';
os.arch = 'x64';
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('fail with unable to parse LTS alias (lts/)', async () => {
// arrange
inputs['node-version'] = 'lts/';

findSpy.mockImplementation(() => '');

// 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(cnSpy).toHaveBeenCalledWith(
`::error::Unable to parse LTS alias for Node version 'lts/'${osm.EOL}`
);
});

it('fail to find LTS version (lts/unknown)', async () => {
// arrange
inputs['node-version'] = 'lts/unknown';

findSpy.mockImplementation(() => '');

// 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).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}`
);
});

it('fail if manifest is not available', async () => {
// 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();

// assert
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}`
);
});
});
});
Loading

0 comments on commit bcb4cec

Please sign in to comment.