fix: add native fallback for addPath

This commit is contained in:
Amin Yahyaabadi 2021-09-18 06:28:04 -05:00
parent 405234b70c
commit a778f9bfce
3 changed files with 21 additions and 6 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

@ -1,15 +1,30 @@
import { addPath as ghAddPath } from "@actions/core" import { addPath as ghAddPath } from "@actions/core"
import { delimiter } from "path" import { delimiter } from "path"
import * as core from "@actions/core" import * as core from "@actions/core"
import { exec } from "@actions/exec"
/** An add path function that works locally or inside GitHub Actions */ /** An add path function that works locally or inside GitHub Actions */
export function addPath(path: string) { export async function addPath(path: string) {
try { try {
ghAddPath(path) ghAddPath(path)
} catch (err) { } catch (err) {
core.error(err as Error) core.error(err as Error)
core.error(`Failed to add ${path} to the percistent PATH. You should add it manually.`) switch (process.platform) {
process.env.PATH = `${path}${delimiter}${process.env.PATH}` case "win32": {
// TODO shell out to add path await exec(`setx PATH=${path};%PATH%`)
break
}
case "linux":
case "darwin": {
await exec(`echo "export PATH=${path}:$PATH" >> ~/.profile`)
await exec(`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}`
}
}
} }
} }