From c4d0bc7f391efe23bb5866f75711fe632023cd29 Mon Sep 17 00:00:00 2001 From: Ben Sterling <25365573+ben-styling@users.noreply.github.com> Date: Wed, 20 Jul 2022 11:17:46 +0100 Subject: [PATCH] fix: add found cached toolpath to PATH before executing node --- __tests__/installer.test.ts | 2 +- src/installer.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3b019e8c..486e1329 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -225,7 +225,7 @@ describe('setup-node', () => { await main.run(); expect(logSpy).toHaveBeenCalledWith( - `Found v14.0.0 in cache @ ${toolPath} but it does not satisfy the requested version (12.16.2)` + `Found v14.0.0 in cache @ ${expPath} but it does not satisfy the requested version (12.16.2)` ); expect(logSpy).toHaveBeenCalledWith( `Attempting to download ${versionSpec}...` diff --git a/src/installer.ts b/src/installer.ts index fae39a8b..bdd593b0 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -82,18 +82,25 @@ export async function getNode( if (toolPath) { core.info(`Found in cache @ ${toolPath}`); + if (osPlat != 'win32') { + toolPath = path.join(toolPath, 'bin'); + } + + core.addPath(toolPath); + 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 (semver.satisfies(installedVersion, versionSpec)) { + return; } + core.info( + `Found ${installedVersion} in cache @ ${toolPath} but it does not satisfy the requested version (${versionSpec})` + ); + toolPath = ''; } if (!toolPath) {