mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 12:03:34 +00:00 
			
		
		
		
	removed test logic in ParseNodeVersionFile for lts and partial matching
This commit is contained in:
		
							parent
							
								
									b1ed0c36e7
								
							
						
					
					
						commit
						c178bbba23
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
import * as core from '@actions/core';
 | 
					import * as core from '@actions/core';
 | 
				
			||||||
import * as io from '@actions/io';
 | 
					import * as io from '@actions/io';
 | 
				
			||||||
import * as tc from '@actions/tool-cache';
 | 
					import * as tc from '@actions/tool-cache';
 | 
				
			||||||
 | 
					import * as im from '../src/installer';
 | 
				
			||||||
import fs from 'fs';
 | 
					import fs from 'fs';
 | 
				
			||||||
import cp from 'child_process';
 | 
					import cp from 'child_process';
 | 
				
			||||||
import osm = require('os');
 | 
					import osm = require('os');
 | 
				
			||||||
@ -9,9 +10,6 @@ import * as main from '../src/main';
 | 
				
			|||||||
import * as auth from '../src/authutil';
 | 
					import * as auth from '../src/authutil';
 | 
				
			||||||
let nodeTestManifest = require('./data/versions-manifest.json');
 | 
					let nodeTestManifest = require('./data/versions-manifest.json');
 | 
				
			||||||
let nodeTestDist = require('./data/node-dist-index.json');
 | 
					let nodeTestDist = require('./data/node-dist-index.json');
 | 
				
			||||||
import * as nv from '../src/installer';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('setup-node', () => {
 | 
					describe('setup-node', () => {
 | 
				
			||||||
  let inputs = {} as any;
 | 
					  let inputs = {} as any;
 | 
				
			||||||
@ -60,8 +58,8 @@ describe('setup-node', () => {
 | 
				
			|||||||
    exSpy = jest.spyOn(tc, 'extractTar');
 | 
					    exSpy = jest.spyOn(tc, 'extractTar');
 | 
				
			||||||
    cacheSpy = jest.spyOn(tc, 'cacheDir');
 | 
					    cacheSpy = jest.spyOn(tc, 'cacheDir');
 | 
				
			||||||
    getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
 | 
					    getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
 | 
				
			||||||
    getDistSpy = jest.spyOn(nv, 'getVersionsFromDist');
 | 
					    getDistSpy = jest.spyOn(im, 'getVersionsFromDist');
 | 
				
			||||||
    parseNodeVersionSpy = jest.spyOn(nv, 'parseNodeVersionFile');
 | 
					    parseNodeVersionSpy = jest.spyOn(im, 'parseNodeVersionFile');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // io
 | 
					    // io
 | 
				
			||||||
    whichSpy = jest.spyOn(io, 'which');
 | 
					    whichSpy = jest.spyOn(io, 'which');
 | 
				
			||||||
@ -77,7 +75,7 @@ describe('setup-node', () => {
 | 
				
			|||||||
    getManifestSpy.mockImplementation(
 | 
					    getManifestSpy.mockImplementation(
 | 
				
			||||||
      () => <tc.IToolRelease[]>nodeTestManifest
 | 
					      () => <tc.IToolRelease[]>nodeTestManifest
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    getDistSpy.mockImplementation(() => <nv.INodeVersion>nodeTestDist);
 | 
					    getDistSpy.mockImplementation(() => <im.INodeVersion>nodeTestDist);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // writes
 | 
					    // writes
 | 
				
			||||||
    cnSpy = jest.spyOn(process.stdout, 'write');
 | 
					    cnSpy = jest.spyOn(process.stdout, 'write');
 | 
				
			||||||
@ -122,7 +120,7 @@ describe('setup-node', () => {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('can mock dist versions', async () => {
 | 
					  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).toBeDefined();
 | 
				
			||||||
    expect(versions?.length).toBe(23);
 | 
					    expect(versions?.length).toBe(23);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
@ -577,7 +575,7 @@ describe('setup-node', () => {
 | 
				
			|||||||
    it('Reads node-version-file if provided', async () => {
 | 
					    it('Reads node-version-file if provided', async () => {
 | 
				
			||||||
      // Arrange
 | 
					      // Arrange
 | 
				
			||||||
      const versionSpec = 'v12';
 | 
					      const versionSpec = 'v12';
 | 
				
			||||||
      const versionFile = '.nvmrc';
 | 
					      const versionFile = '.immrc';
 | 
				
			||||||
      const expectedVersionSpec = '12';
 | 
					      const expectedVersionSpec = '12';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      inputs['node-version-file'] = versionFile;
 | 
					      inputs['node-version-file'] = versionFile;
 | 
				
			||||||
@ -596,310 +594,267 @@ describe('setup-node', () => {
 | 
				
			|||||||
      );
 | 
					      );
 | 
				
			||||||
      expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
 | 
					      expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
 | 
				
			||||||
      expect(logSpy).toHaveBeenCalledWith(
 | 
					      expect(logSpy).toHaveBeenCalledWith(
 | 
				
			||||||
        `Resolved ${versionFile} as ${expectedVersionSpec}`);
 | 
					        `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}`
 | 
					 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    describe('LTS version', () => {
 | 
				
			||||||
    it('find latest LTS version and install it from manifest (lts/erbium)', async () => {
 | 
					      beforeEach(() => {
 | 
				
			||||||
      // arrange
 | 
					        os.platform = 'linux';
 | 
				
			||||||
      inputs['node-version'] = 'lts/erbium';
 | 
					        os.arch = 'x64';
 | 
				
			||||||
 | 
					        inputs.stable = 'true';
 | 
				
			||||||
      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
 | 
					      it('find latest LTS version and resolve it from local cache (lts/erbium)', async () => {
 | 
				
			||||||
      await main.run();
 | 
					        // arrange
 | 
				
			||||||
 | 
					        inputs['node-version'] = 'lts/erbium';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // assert
 | 
					        const toolPath = path.normalize('/cache/node/12.16.2/x64');
 | 
				
			||||||
      expect(logSpy).toHaveBeenCalledWith(
 | 
					        findSpy.mockReturnValue(toolPath);
 | 
				
			||||||
        'Attempt to resolve LTS alias from manifest...'
 | 
					
 | 
				
			||||||
      );
 | 
					        // act
 | 
				
			||||||
      expect(dbgSpy).toHaveBeenCalledWith(
 | 
					        await main.run();
 | 
				
			||||||
        'Getting manifest from actions/node-versions@main'
 | 
					
 | 
				
			||||||
      );
 | 
					        // assert
 | 
				
			||||||
      expect(cnSpy).toHaveBeenCalledWith(
 | 
					        expect(logSpy).toHaveBeenCalledWith(
 | 
				
			||||||
        `::error::Unable to download manifest${osm.EOL}`
 | 
					          '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) {
 | 
					function parseNodeVersionFile(contents) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        contents = contents.trim();
 | 
					        let nodeVersion = contents.trim();
 | 
				
			||||||
        if (/^v\d/.test(contents)) {
 | 
					        if (/^v\d/.test(nodeVersion)) {
 | 
				
			||||||
            contents = contents.substring(1);
 | 
					            nodeVersion = nodeVersion.substring(1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const nodeVersions = yield getVersionsFromDist();
 | 
					        return nodeVersion;
 | 
				
			||||||
        let nodeVersion;
 | 
					 | 
				
			||||||
        if (semver.valid(contents) || isPartialMatch(contents)) {
 | 
					 | 
				
			||||||
            nodeVersion = contents;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            throw new Error(`Couldn't resolve node version: '${contents}'`);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return stripVPrefix(nodeVersion);
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
 | 
					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;
 | 
					  return nodeVersion;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										91
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										91
									
								
								src/main.ts
									
									
									
									
									
								
							@ -28,54 +28,55 @@ export async function run() {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
        core.info(`Resolved ${versionFile} as ${version}`);
 | 
					        core.info(`Resolved ${versionFile} as ${version}`);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    let arch = core.getInput('architecture');
 | 
					      let arch = core.getInput('architecture');
 | 
				
			||||||
    const cache = core.getInput('cache');
 | 
					      const cache = core.getInput('cache');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // if architecture supplied but node-version is not
 | 
					      // 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 we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
 | 
				
			||||||
    if (arch && !version) {
 | 
					      if (arch && !version) {
 | 
				
			||||||
      core.warning(
 | 
					        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`'
 | 
					          '`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')}`
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
    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) {
 | 
					 | 
				
			||||||
    core.setFailed(error.message);
 | 
					    core.setFailed(error.message);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user