mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
removed test logic in ParseNodeVersionFile for lts and partial matching
This commit is contained in:
parent
b1ed0c36e7
commit
c178bbba23
4 changed files with 312 additions and 373 deletions
|
@ -1,6 +1,7 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as im from '../src/installer';
|
||||
import fs from 'fs';
|
||||
import cp from 'child_process';
|
||||
import osm = require('os');
|
||||
|
@ -9,9 +10,6 @@ import * as main from '../src/main';
|
|||
import * as auth from '../src/authutil';
|
||||
let nodeTestManifest = require('./data/versions-manifest.json');
|
||||
let nodeTestDist = require('./data/node-dist-index.json');
|
||||
import * as nv from '../src/installer';
|
||||
|
||||
|
||||
|
||||
describe('setup-node', () => {
|
||||
let inputs = {} as any;
|
||||
|
@ -60,8 +58,8 @@ describe('setup-node', () => {
|
|||
exSpy = jest.spyOn(tc, 'extractTar');
|
||||
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
||||
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
||||
getDistSpy = jest.spyOn(nv, 'getVersionsFromDist');
|
||||
parseNodeVersionSpy = jest.spyOn(nv, 'parseNodeVersionFile');
|
||||
getDistSpy = jest.spyOn(im, 'getVersionsFromDist');
|
||||
parseNodeVersionSpy = jest.spyOn(im, 'parseNodeVersionFile');
|
||||
|
||||
// io
|
||||
whichSpy = jest.spyOn(io, 'which');
|
||||
|
@ -77,7 +75,7 @@ describe('setup-node', () => {
|
|||
getManifestSpy.mockImplementation(
|
||||
() => <tc.IToolRelease[]>nodeTestManifest
|
||||
);
|
||||
getDistSpy.mockImplementation(() => <nv.INodeVersion>nodeTestDist);
|
||||
getDistSpy.mockImplementation(() => <im.INodeVersion>nodeTestDist);
|
||||
|
||||
// writes
|
||||
cnSpy = jest.spyOn(process.stdout, 'write');
|
||||
|
@ -122,7 +120,7 @@ describe('setup-node', () => {
|
|||
});
|
||||
|
||||
it('can mock dist versions', async () => {
|
||||
let versions: nv.INodeVersion[] = await nv.getVersionsFromDist();
|
||||
let versions: im.INodeVersion[] = await im.getVersionsFromDist();
|
||||
expect(versions).toBeDefined();
|
||||
expect(versions?.length).toBe(23);
|
||||
});
|
||||
|
@ -577,7 +575,7 @@ describe('setup-node', () => {
|
|||
it('Reads node-version-file if provided', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'v12';
|
||||
const versionFile = '.nvmrc';
|
||||
const versionFile = '.immrc';
|
||||
const expectedVersionSpec = '12';
|
||||
|
||||
inputs['node-version-file'] = versionFile;
|
||||
|
@ -596,310 +594,267 @@ describe('setup-node', () => {
|
|||
);
|
||||
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
|
||||
expect(logSpy).toHaveBeenCalledWith(
|
||||
`Resolved ${versionFile} as ${expectedVersionSpec}`);
|
||||
});
|
||||
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}`
|
||||
`Resolved ${versionFile} as ${expectedVersionSpec}`
|
||||
);
|
||||
});
|
||||
|
||||
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');
|
||||
describe('LTS version', () => {
|
||||
beforeEach(() => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
inputs.stable = 'true';
|
||||
});
|
||||
|
||||
// act
|
||||
await main.run();
|
||||
it('find latest LTS version and resolve it from local cache (lts/erbium)', async () => {
|
||||
// arrange
|
||||
inputs['node-version'] = 'lts/erbium';
|
||||
|
||||
// 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}`
|
||||
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}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('node-version-file', () => {
|
||||
let getVersionsFromDist: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
// @actions/core
|
||||
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
|
||||
|
||||
getVersionsFromDist = jest.spyOn(im, 'getVersionsFromDist');
|
||||
|
||||
// gets
|
||||
getVersionsFromDist.mockImplementation(
|
||||
() => <im.INodeVersion>nodeTestDist
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
//jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
|
||||
}, 100000);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Manifest find tests
|
||||
//--------------------------------------------------
|
||||
describe('parseNodeVersionFile', () => {
|
||||
it('without `v` prefix', async () => {
|
||||
// Arrange
|
||||
const versionSpec = '12';
|
||||
|
||||
// Act
|
||||
const result = await im.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(versionSpec);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('node-version-file', () => {
|
||||
let getVersionsFromDist: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
// @actions/core
|
||||
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
|
||||
|
||||
getVersionsFromDist = jest.spyOn(nv, 'getVersionsFromDist');
|
||||
|
||||
// gets
|
||||
getVersionsFromDist.mockImplementation(() => <nv.INodeVersion>nodeTestDist);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
//jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
|
||||
}, 100000);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Manifest find tests
|
||||
//--------------------------------------------------
|
||||
describe('parseNodeVersionFile', () => {
|
||||
it('without `v` prefix', async () => {
|
||||
// Arrange
|
||||
const versionSpec = '12';
|
||||
|
||||
// Act
|
||||
const result = await nv.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(versionSpec);
|
||||
});
|
||||
|
||||
it('lts/*', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'lts/*';
|
||||
|
||||
// Act
|
||||
const result = await nv.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toMatch(/^\d+\.\d+\.\d+$/);
|
||||
});
|
||||
|
||||
it('lts/erbium', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'lts/*';
|
||||
|
||||
// Act
|
||||
const result = await nv.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toMatch(/\d\.\d\.\d/);
|
||||
});
|
||||
|
||||
it('partial syntax like 12', async () => {
|
||||
// Arrange
|
||||
const versionSpec = '12';
|
||||
|
||||
// Act
|
||||
const result = await nv.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(versionSpec);
|
||||
});
|
||||
|
||||
it('partial syntax like 12.16', async () => {
|
||||
// Arrange
|
||||
const versionSpec = '12.16';
|
||||
|
||||
// Act
|
||||
const result = await nv.parseNodeVersionFile(versionSpec);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(versionSpec);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
22
dist/setup/index.js
vendored
22
dist/setup/index.js
vendored
|
@ -65412,28 +65412,14 @@ function translateArchToDistUrl(arch) {
|
|||
}
|
||||
function parseNodeVersionFile(contents) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
contents = contents.trim();
|
||||
if (/^v\d/.test(contents)) {
|
||||
contents = contents.substring(1);
|
||||
let nodeVersion = contents.trim();
|
||||
if (/^v\d/.test(nodeVersion)) {
|
||||
nodeVersion = nodeVersion.substring(1);
|
||||
}
|
||||
const nodeVersions = yield getVersionsFromDist();
|
||||
let nodeVersion;
|
||||
if (semver.valid(contents) || isPartialMatch(contents)) {
|
||||
nodeVersion = contents;
|
||||
}
|
||||
else {
|
||||
throw new Error(`Couldn't resolve node version: '${contents}'`);
|
||||
}
|
||||
return stripVPrefix(nodeVersion);
|
||||
return nodeVersion;
|
||||
});
|
||||
}
|
||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||
function isPartialMatch(version) {
|
||||
return /^\d+(\.\d+(\.\d+)?)?$/.test(version);
|
||||
}
|
||||
function stripVPrefix(version) {
|
||||
return /^v\d/.test(version) ? version.substring(1) : version;
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -474,6 +474,3 @@ export async function parseNodeVersionFile(contents: string): Promise<string> {
|
|||
}
|
||||
return nodeVersion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
93
src/main.ts
93
src/main.ts
|
@ -28,54 +28,55 @@ export async function run() {
|
|||
);
|
||||
core.info(`Resolved ${versionFile} as ${version}`);
|
||||
}
|
||||
let arch = core.getInput('architecture');
|
||||
const cache = core.getInput('cache');
|
||||
let arch = core.getInput('architecture');
|
||||
const cache = core.getInput('cache');
|
||||
|
||||
// if architecture supplied but node-version is not
|
||||
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
|
||||
if (arch && !version) {
|
||||
core.warning(
|
||||
'`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
|
||||
// if architecture supplied but node-version is not
|
||||
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
|
||||
if (arch && !version) {
|
||||
core.warning(
|
||||
'`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
|
||||
);
|
||||
}
|
||||
|
||||
if (!arch) {
|
||||
arch = os.arch();
|
||||
}
|
||||
|
||||
if (version) {
|
||||
let token = core.getInput('token');
|
||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||
let stable =
|
||||
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||
const checkLatest =
|
||||
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||
await installer.getNode(version, stable, checkLatest, auth, arch);
|
||||
}
|
||||
|
||||
const registryUrl: string = core.getInput('registry-url');
|
||||
const alwaysAuth: string = core.getInput('always-auth');
|
||||
if (registryUrl) {
|
||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
|
||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
||||
core.info(
|
||||
`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`
|
||||
);
|
||||
core.info(
|
||||
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!arch) {
|
||||
arch = os.arch();
|
||||
}
|
||||
|
||||
if (version) {
|
||||
let token = core.getInput('token');
|
||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||
const checkLatest =
|
||||
(core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||
await installer.getNode(version, stable, checkLatest, auth, arch);
|
||||
}
|
||||
|
||||
const registryUrl: string = core.getInput('registry-url');
|
||||
const alwaysAuth: string = core.getInput('always-auth');
|
||||
if (registryUrl) {
|
||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
|
||||
const matchersPath = path.join(__dirname, '../..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
|
||||
core.info(
|
||||
`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`
|
||||
);
|
||||
core.info(
|
||||
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +86,4 @@ function isGhes(): boolean {
|
|||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue