mirror of https://github.com/aminya/setup-cpp
fix: use sudo if available on linux
This commit is contained in:
parent
c6aac2897f
commit
edbc293b98
|
@ -5,12 +5,15 @@ let didUpdate: boolean = false
|
|||
|
||||
/** A function that installs a package using apt */
|
||||
export async function setupAptPack(name: string, version?: string, updateRepositories: boolean = true) {
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
|
||||
const apt = process.env.CI || process.getuid?.() === 0 ? "sudo apt-get" : "apt-get"
|
||||
|
||||
if (!didUpdate || updateRepositories) {
|
||||
await exec("apt-get", ["update"])
|
||||
await exec(apt, ["update"])
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
const exit = await exec("apt-get", ["install", version !== undefined ? `${name}=${version}` : name])
|
||||
const exit = await exec(apt, ["install", version !== undefined ? `${name}=${version}` : name])
|
||||
|
||||
if (exit !== 0) {
|
||||
throw new Error(`Failed to install ${name} ${version}`)
|
||||
|
|
Loading…
Reference in New Issue