fix: use the user profile to add system environment variables

This commit is contained in:
Amin Yahyaabadi 2022-01-19 11:43:35 -08:00
parent 3a91e6f67a
commit 469230d988
3 changed files with 11 additions and 3 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

@ -4,6 +4,8 @@ import execa from "execa"
import { isGitHubCI } from "./isci" import { isGitHubCI } from "./isci"
import untildify from "untildify" import untildify from "untildify"
import { appendFileSync } from "fs" import { appendFileSync } from "fs"
import { join } from "path"
import { isRoot } from "./sudo"
/** An add path function that works locally or inside GitHub Actions */ /** An add path function that works locally or inside GitHub Actions */
export function addEnv(name: string, val: string | undefined) { export function addEnv(name: string, val: string | undefined) {
@ -33,7 +35,13 @@ function addEnvSystem(name: string, val: string | undefined) {
} }
case "linux": case "linux":
case "darwin": { 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`) appendFileSync(profile_path, `\nexport ${name}="${val}"\n`)
core.info(`${name}="${val} was added to "${profile_path}"`) core.info(`${name}="${val} was added to "${profile_path}"`)
return return