fix: use sudo-tools in setup-cpp

This commit is contained in:
Amin Yahyaabadi 2022-08-07 17:24:44 -07:00
parent fe2db9dd25
commit 299694053d
16 changed files with 22 additions and 50 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

2
dist/setup_cpp.mjs 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

@ -62,6 +62,7 @@
"numerous": "1.0.3", "numerous": "1.0.3",
"semver": "7.3.7", "semver": "7.3.7",
"setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d", "setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d",
"sudo-tools": "workspace:*",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e", "time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
"ubuntu-version": "^2.0.0", "ubuntu-version": "^2.0.0",
"untildify": "^4.0.0", "untildify": "^4.0.0",

View File

@ -28,14 +28,16 @@ export function prependSudo(command: string) {
/** /**
* Execute a command as sudo if sudo is available. Otherwise executes the command without sudo. * Execute a command as sudo if sudo is available. Otherwise executes the command without sudo.
* *
* @param file The file to spawn * @param program The program to spawn
* @param args The command arguments * @param args The command arguments
* @param execOptions The options passed to `execa`. * @param execOptions The options passed to `execa`.
*
* Defaults to `{ stdio: "inherit" }`
*/ */
export function execSudo(file: string, args: string[], execOptions: execa.SyncOptions = { stdio: "inherit" }) { export function execSudo(program: string, args: string[] = [], execOptions: execa.SyncOptions = { stdio: "inherit" }) {
if (isRoot()) { if (isRoot()) {
return execa.commandSync(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions) return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
} else { } else {
return execa.sync(file, args, execOptions) return execa.sync(program, args, execOptions)
} }
} }

View File

@ -44,6 +44,7 @@ importers:
semver: 7.3.7 semver: 7.3.7
setup-python: github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d setup-python: github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d
shx: 0.3.4 shx: 0.3.4
sudo-tools: workspace:*
terser-config-atomic: ^0.1.1 terser-config-atomic: ^0.1.1
time-delta: github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e time-delta: github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e
ts-jest: ^28.0.7 ts-jest: ^28.0.7
@ -64,6 +65,7 @@ importers:
numerous: 1.0.3 numerous: 1.0.3
semver: 7.3.7 semver: 7.3.7
setup-python: github.com/actions/setup-python/c474c82340438924daab9282d07300bfe7e3692d setup-python: github.com/actions/setup-python/c474c82340438924daab9282d07300bfe7e3692d
sudo-tools: link:packages/sudo-tools
time-delta: github.com/aminya/time-delta/69d91a41cef28e569be9a2991129f5f7d1f0d00e time-delta: github.com/aminya/time-delta/69d91a41cef28e569be9a2991129f5f7d1f0d00e
ubuntu-version: 2.0.0 ubuntu-version: 2.0.0
untildify: 4.0.0 untildify: 4.0.0

View File

@ -5,7 +5,7 @@ import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf" import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execSudo } from "../utils/exec/sudo" import { execSudo } from "sudo-tools"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupBazel(version: string, _setupDir: string, _arch: string) { export async function setupBazel(version: string, _setupDir: string, _arch: string) {

View File

@ -1,7 +1,7 @@
import { dirname } from "path" import { dirname } from "path"
import which from "which" import which from "which"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execSudo } from "../utils/exec/sudo" import { execSudo } from "sudo-tools"
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack" import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
let binDir: string | undefined let binDir: string | undefined

19
src/utils/env/sudo.ts vendored
View File

@ -1,19 +0,0 @@
import which from "which"
let _issudo: boolean | undefined = undefined
export function isRoot(): boolean {
if (_issudo !== undefined) {
return _issudo
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
_issudo = (Boolean(process.env.CI) || process.getuid?.() === 0) && which.sync("sudo", { nothrow: true }) !== null
return _issudo
}
export function mightSudo(command: string) {
if (isRoot()) {
return `sudo ${command}`
}
return command
}

View File

@ -1,14 +0,0 @@
import execa from "execa"
import { isRoot } from "../env/sudo"
export function execSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.commandSync(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, {
shell: true,
cwd,
stdio: "inherit",
})
} else {
return execa.sync(file, args, { stdio: "inherit" })
}
}

View File

@ -1,5 +1,5 @@
import { isRoot } from "../env/sudo" import { isRoot } from "sudo-tools"
import { execSudo } from "../exec/sudo" import { execSudo } from "sudo-tools"
/// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo /// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo
export function folderUserAccess(folder: string) { export function folderUserAccess(folder: string) {
@ -8,6 +8,6 @@ export function folderUserAccess(folder: string) {
isRoot() && isRoot() &&
process.env.SUDO_USER !== undefined process.env.SUDO_USER !== undefined
) { ) {
execSudo("chown", ["-R", process.env.SUDO_USER, folder], folder) execSudo("chown", ["-R", process.env.SUDO_USER, folder], { cwd: folder, stdio: "inherit" })
} }
} }

View File

@ -1,6 +1,6 @@
import { join } from "path" import { join } from "path"
import untildify from "untildify" import untildify from "untildify"
import { isRoot } from "../env/sudo" import { isRoot } from "sudo-tools"
export function untildify_user(path: string) { export function untildify_user(path: string) {
if (isRoot() && typeof process.env.SUDO_USER === "string") { if (isRoot() && typeof process.env.SUDO_USER === "string") {

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo" import { execSudo } from "sudo-tools"
import { info } from "@actions/core" import { info } from "@actions/core"
import { isGitHubCI } from "../env/isCI" import { isGitHubCI } from "../env/isCI"
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv" import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo" import { execSudo } from "sudo-tools"
import { info, warning } from "../io/io" import { info, warning } from "../io/io"
// let didUpdate: boolean = false // let didUpdate: boolean = false

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo" import { execSudo } from "sudo-tools"
import { info } from "../io/io" import { info } from "../io/io"
let didUpdate: boolean = false let didUpdate: boolean = false