fix: try-catch adding path using system

This commit is contained in:
Amin Yahyaabadi 2021-09-18 10:38:48 -05:00
parent d749362c4e
commit d81b44b112
1 changed files with 21 additions and 16 deletions

View File

@ -8,23 +8,28 @@ export async function addPath(path: string) {
try {
ghAddPath(path)
} catch (err) {
core.error(err as Error)
switch (process.platform) {
case "win32": {
await execa(`setx PATH=${path};%PATH%`)
break
}
case "linux":
case "darwin": {
await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
await execa.command(`source ~/.profile`)
core.info(`${path} was added to ~/.profile`)
break
}
default: {
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`)
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try {
core.error(err as Error)
switch (process.platform) {
case "win32": {
await execa(`setx PATH=${path};%PATH%`)
return
}
case "linux":
case "darwin": {
await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
await execa.command(`source ~/.profile`)
core.info(`${path} was added to ~/.profile`)
return
}
default: {
// fall through shell path modification
}
}
} catch (err2) {
core.error(err2 as Error)
}
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`)
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
}
}