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 { try {
ghAddPath(path) ghAddPath(path)
} catch (err) { } catch (err) {
core.error(err as Error) try {
switch (process.platform) { core.error(err as Error)
case "win32": { switch (process.platform) {
await execa(`setx PATH=${path};%PATH%`) case "win32": {
break await execa(`setx PATH=${path};%PATH%`)
} return
case "linux": }
case "darwin": { case "linux":
await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`) case "darwin": {
await execa.command(`source ~/.profile`) await execa.command(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
core.info(`${path} was added to ~/.profile`) await execa.command(`source ~/.profile`)
break core.info(`${path} was added to ~/.profile`)
} return
default: { }
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`) default: {
process.env.PATH = `${path}${delimiter}${process.env.PATH}` // 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}`
} }
} }