fix: use powershell for val.length of more than 1024

This commit is contained in:
Amin Yahyaabadi 2022-01-22 20:39:08 -08:00
parent 946065a48d
commit d67d7e0c03
4 changed files with 14 additions and 5 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -26,10 +26,15 @@ export function addEnv(name: string, val: string | undefined) {
} }
} }
function addEnvSystem(name: string, val: string | undefined) { function addEnvSystem(name: string, valGiven: string | undefined) {
const val = valGiven ?? ""
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
if (val.length <= 1024) {
execa.sync(`setx "${name}" "${val}"`) execa.sync(`setx "${name}" "${val}"`)
} else {
execa.sync(`powershell -C "[Environment]::SetEnvironmentVariable('${name}', '${val}', 'User')"`)
}
core.info(`${name}="${val} was set in the environment."`) core.info(`${name}="${val} was set in the environment."`)
return return
} }

View File

@ -28,7 +28,11 @@ export function addPath(path: string) {
function addPathSystem(path: string) { function addPathSystem(path: string) {
switch (process.platform) { switch (process.platform) {
case "win32": { case "win32": {
if (`${path};${process.env.PATH}`.length <= 1024) {
execa.sync(`setx PATH "${path};%PATH%"`) execa.sync(`setx PATH "${path};%PATH%"`)
} else {
execa.sync(`powershell -C "[Environment]::SetEnvironmentVariable('PATH', \\"${path};$env:PATH\\", 'User')"`)
}
core.info(`${path} was added to the PATH.`) core.info(`${path} was added to the PATH.`)
return return
} }