Skip to content

Commit 469230d

Browse files
committed
fix: use the user profile to add system environment variables
1 parent 3a91e6f commit 469230d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/env/addEnv.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import execa from "execa"
44
import { isGitHubCI } from "./isci"
55
import untildify from "untildify"
66
import { appendFileSync } from "fs"
7+
import { join } from "path"
8+
import { isRoot } from "./sudo"
79

810
/** An add path function that works locally or inside GitHub Actions */
911
export function addEnv(name: string, val: string | undefined) {
@@ -33,7 +35,13 @@ function addEnvSystem(name: string, val: string | undefined) {
3335
}
3436
case "linux":
3537
case "darwin": {
36-
const profile_path = untildify("~/.profile")
38+
// find profile path
39+
let profile_path = untildify("~/.profile")
40+
if (isRoot() && typeof process.env.SUDO_USER === "string") {
41+
// use the user profile even if root
42+
profile_path = join("/home/", process.env.SUDO_USER, ".profile")
43+
}
44+
3745
appendFileSync(profile_path, `\nexport ${name}="${val}"\n`)
3846
core.info(`${name}="${val} was added to "${profile_path}"`)
3947
return

0 commit comments

Comments
 (0)