From b4b3a68a120ee08da54d1f68c6ede66f075089bf Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 23 Oct 2021 19:06:12 +0000 Subject: [PATCH] Export the `Path` variable rather than appending to it The `addPath` will invert the path ordering as each entry is appended to the environment file, which is then reversed and prepended to the environment at the end of the action. This results in the additions being in reverse order. However, since we know that `vsdevcmd` will adjust the path on both ends, simply prefer to use the `exportVariable` rather than try to be clever to adjust the path via `addPath`. Fixes: #10. --- index.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index a591e98..f6dea80 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ try { const vsDevCmdPath = path.win32.join(installPath, 'Common7', 'Tools', 'vsdevcmd.bat') console.log(`vsdevcmd: ${vsDevCmdPath}`) - const vsDevCmdArgs = [ vsDevCmdPath, `-arch=${arch}` ] + const vsDevCmdArgs = [vsDevCmdPath, `-arch=${arch}` ] if (hostArch != '') vsDevCmdArgs.push(`-host_arch=${hostArch}`) if (toolsetVersion != '') @@ -55,12 +55,14 @@ try { if (winsdk != '') vsDevCmdArgs.push(`-winsdk=${winsdk}`) - const cmdArgs = [ '/q', '/k'].concat(vsDevCmdArgs, ['&&', 'set']) - + const cmdArgs = ['/q', '/k'].concat(vsDevCmdArgs, ['&&', 'set']) console.log(`$ cmd ${cmdArgs.join(' ')}`) + console.log("running ...") const cmdResult = spawn('cmd', cmdArgs, {encoding: 'utf8'}) + console.log(`cmdResult: ${cmdResult}`) if (cmdResult.error) throw cmdResult.error + const cmdOutput = cmdResult.output .filter(s => !!s) .map(s => s.split('\n')) @@ -71,25 +73,12 @@ try { const completeEnv = cmdOutput .filter(s => s.indexOf('=') != -1) .map(s => s.split('=', 2)) - const filteredEnv = completeEnv - .filter(([key, _]) => key != 'Path' && !process.env[key]) + const filteredEnv = completeEnv.filter(!process.env[key]) for (const [key, value] of filteredEnv) { + console.log(`Setting ${key} => ${value}`) core.exportVariable(key, value) } - - const pathEntries = process.env['Path'].split(';') - const newPathEntries = completeEnv - .filter(([key, _]) => key == 'Path') - .map(([_, value]) => value) - .join(';') - .split(';') - .filter(path => pathEntries.indexOf(path) == -1) - - for (const path of newPathEntries) { - core.addPath(path) - } - console.log('environment updated') } catch (error) { core.setFailed(error.message);