mirror of https://github.com/aminya/setup-cpp
fix: use the user profile to add system environment variables
This commit is contained in:
parent
3a91e6f67a
commit
469230d988
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,8 @@ import execa from "execa"
|
|||
import { isGitHubCI } from "./isci"
|
||||
import untildify from "untildify"
|
||||
import { appendFileSync } from "fs"
|
||||
import { join } from "path"
|
||||
import { isRoot } from "./sudo"
|
||||
|
||||
/** An add path function that works locally or inside GitHub Actions */
|
||||
export function addEnv(name: string, val: string | undefined) {
|
||||
|
@ -33,7 +35,13 @@ function addEnvSystem(name: string, val: string | undefined) {
|
|||
}
|
||||
case "linux":
|
||||
case "darwin": {
|
||||
const profile_path = untildify("~/.profile")
|
||||
// find profile path
|
||||
let profile_path = untildify("~/.profile")
|
||||
if (isRoot() && typeof process.env.SUDO_USER === "string") {
|
||||
// use the user profile even if root
|
||||
profile_path = join("/home/", process.env.SUDO_USER, ".profile")
|
||||
}
|
||||
|
||||
appendFileSync(profile_path, `\nexport ${name}="${val}"\n`)
|
||||
core.info(`${name}="${val} was added to "${profile_path}"`)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue