Skip to content

Commit

Permalink
Export the Path variable rather than appending to it
Browse files Browse the repository at this point in the history
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: seanmiddleditch#10.
  • Loading branch information
compnerd authored Oct 23, 2021
1 parent 6922ba6 commit c756839
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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);
Expand Down

0 comments on commit c756839

Please sign in to comment.