mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:43:35 +00:00 
			
		
		
		
	re-download if cached version is incorrect
This commit is contained in:
		
							parent
							
								
									5b949b50c3
								
							
						
					
					
						commit
						c5f0b687c5
					
				@ -205,6 +205,27 @@ describe('setup-node', () => {
 | 
			
		||||
    expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('finds incorrect version in cache and adds it to the path', async () => {
 | 
			
		||||
    let versionSpec = '12.16.2';
 | 
			
		||||
    inputs['node-version'] = versionSpec;
 | 
			
		||||
 | 
			
		||||
    inSpy.mockImplementation(name => inputs[name]);
 | 
			
		||||
    getExecOutputSpy.mockImplementation(() => 'v12.0.0');
 | 
			
		||||
 | 
			
		||||
    let toolPath = path.normalize('/cache/node/12.16.1/x64');
 | 
			
		||||
    findSpy.mockImplementation(() => toolPath);
 | 
			
		||||
    await main.run();
 | 
			
		||||
 | 
			
		||||
    let expPath = path.join(toolPath, 'bin');
 | 
			
		||||
    expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `Found v12.0.0 in cache @ ${toolPath} but it does not satisfy the requested version (${versionSpec})`
 | 
			
		||||
    );
 | 
			
		||||
    expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `Attempting to download ${versionSpec}...`
 | 
			
		||||
    );
 | 
			
		||||
    expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('handles unhandled find error and reports error', async () => {
 | 
			
		||||
    let errMsg = 'unhandled error message';
 | 
			
		||||
    inputs['node-version'] = '12';
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -71409,6 +71409,7 @@ const core = __importStar(__nccwpck_require__(2186));
 | 
			
		||||
const hc = __importStar(__nccwpck_require__(9925));
 | 
			
		||||
const io = __importStar(__nccwpck_require__(7436));
 | 
			
		||||
const tc = __importStar(__nccwpck_require__(7784));
 | 
			
		||||
const exec = __importStar(__nccwpck_require__(1514));
 | 
			
		||||
const path = __importStar(__nccwpck_require__(1017));
 | 
			
		||||
const semver = __importStar(__nccwpck_require__(5911));
 | 
			
		||||
const fs = __nccwpck_require__(7147);
 | 
			
		||||
@ -71447,8 +71448,13 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
			
		||||
        // If not found in cache, download
 | 
			
		||||
        if (toolPath) {
 | 
			
		||||
            core.info(`Found in cache @ ${toolPath}`);
 | 
			
		||||
            const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true });
 | 
			
		||||
            if (!semver.satisfies(installedVersion, versionSpec)) {
 | 
			
		||||
                core.info(`Found ${installedVersion} in cache @ ${toolPath} but it does not satisfy the requested version (${versionSpec})`);
 | 
			
		||||
                toolPath = '';
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        if (!toolPath) {
 | 
			
		||||
            core.info(`Attempting to download ${versionSpec}...`);
 | 
			
		||||
            let downloadPath = '';
 | 
			
		||||
            let info = null;
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ import * as core from '@actions/core';
 | 
			
		||||
import * as hc from '@actions/http-client';
 | 
			
		||||
import * as io from '@actions/io';
 | 
			
		||||
import * as tc from '@actions/tool-cache';
 | 
			
		||||
import * as exec from '@actions/exec';
 | 
			
		||||
import * as path from 'path';
 | 
			
		||||
import * as semver from 'semver';
 | 
			
		||||
import fs = require('fs');
 | 
			
		||||
@ -80,7 +81,22 @@ export async function getNode(
 | 
			
		||||
  // If not found in cache, download
 | 
			
		||||
  if (toolPath) {
 | 
			
		||||
    core.info(`Found in cache @ ${toolPath}`);
 | 
			
		||||
  } else {
 | 
			
		||||
 | 
			
		||||
    const {stdout: installedVersion} = await exec.getExecOutput(
 | 
			
		||||
      'node',
 | 
			
		||||
      ['--version'],
 | 
			
		||||
      {ignoreReturnCode: true}
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!semver.satisfies(installedVersion, versionSpec)) {
 | 
			
		||||
      core.info(
 | 
			
		||||
        `Found ${installedVersion} in cache @ ${toolPath} but it does not satisfy the requested version (${versionSpec})`
 | 
			
		||||
      );
 | 
			
		||||
      toolPath = '';
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!toolPath) {
 | 
			
		||||
    core.info(`Attempting to download ${versionSpec}...`);
 | 
			
		||||
    let downloadPath = '';
 | 
			
		||||
    let info: INodeVersionInfo | null = null;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user