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 { 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
|
||||||
|
|
Loading…
Reference in New Issue