mirror of https://github.com/aminya/setup-cpp
feat: add support for adding repositories to apt
This commit is contained in:
parent
8ab3e55ee8
commit
cf3dbb2b16
|
@ -1,19 +1,23 @@
|
||||||
/* eslint-disable require-atomic-updates */
|
/* eslint-disable require-atomic-updates */
|
||||||
import { exec } from "@actions/exec"
|
import { exec } from "@actions/exec"
|
||||||
|
import { mightSudo } from "./sudo"
|
||||||
|
|
||||||
let didUpdate: boolean = false
|
let didUpdate: boolean = false
|
||||||
|
|
||||||
/** A function that installs a package using apt */
|
/** A function that installs a package using apt */
|
||||||
export async function setupAptPack(name: string, version?: string, updateRepositories: boolean = true) {
|
export async function setupAptPack(name: string, version?: string, repository: boolean | string = true) {
|
||||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
|
const apt = mightSudo("apt-get")
|
||||||
const apt = process.env.CI || process.getuid?.() === 0 ? "sudo apt-get" : "apt-get"
|
|
||||||
|
|
||||||
if (!didUpdate || updateRepositories) {
|
let exit = 0
|
||||||
|
|
||||||
|
if (!didUpdate || repository === true) {
|
||||||
await exec(apt, ["update"])
|
await exec(apt, ["update"])
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
|
} else if (typeof repository === "string") {
|
||||||
|
exit = await exec(mightSudo("add-apt-repository"), ["--update", repository])
|
||||||
}
|
}
|
||||||
|
|
||||||
const exit = await exec(apt, ["install", version !== undefined && version !== "" ? `${name}=${version}` : name])
|
exit = await exec(apt, ["install", version !== undefined && version !== "" ? `${name}=${version}` : name])
|
||||||
|
|
||||||
if (exit !== 0) {
|
if (exit !== 0) {
|
||||||
throw new Error(`Failed to install ${name} ${version}`)
|
throw new Error(`Failed to install ${name} ${version}`)
|
||||||
|
|
Loading…
Reference in New Issue