fix: add found cached toolpath to PATH before executing node

This commit is contained in:
Ben Sterling 2022-07-20 11:17:46 +01:00
parent df568f01a8
commit c4d0bc7f39
No known key found for this signature in database
GPG Key ID: 4A6610DCFFC78977
2 changed files with 13 additions and 6 deletions

View File

@ -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}...`

View File

@ -82,19 +82,26 @@ 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)) {
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) {
core.info(`Attempting to download ${versionSpec}...`);