Skip to content

Commit 0dbc7a0

Browse files
committed
fix: refactor apt functions into separate files
1 parent adb1af1 commit 0dbc7a0

File tree

16 files changed

+296
-277
lines changed

16 files changed

+296
-277
lines changed

dist/actions/setup-cpp.js

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/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.

dist/legacy/setup-cpp.js

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/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.

dist/modern/setup-cpp.js

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/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.

packages/setup-apt/src/apt-env.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Get the environment variables to use for the apt command
3+
* @param apt The apt command to use
4+
* @private Used internally
5+
*/
6+
7+
export function getAptEnv(apt: string) {
8+
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
9+
10+
if (apt === "nala") {
11+
// if LANG/LC_ALL is not set, enable utf8 otherwise nala fails because of ASCII encoding
12+
if (env.LANG === undefined) {
13+
env.LANG = "C.UTF-8"
14+
}
15+
if (env.LC_ALL === undefined) {
16+
env.LC_ALL = "C.UTF-8"
17+
}
18+
}
19+
20+
return env
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defaultExecOptions, execRootSync } from "admina"
2+
import { getAptEnv } from "./apt-env.js"
3+
import { aptTimeout } from "./apt-timeout.js"
4+
import { getApt } from "./get-apt.js"
5+
import { isAptPackInstalled } from "./is-installed.js"
6+
import { updateAptRepos } from "./update.js"
7+
8+
export async function addAptRepository(repo: string, apt = getApt()) {
9+
await installAddAptRepo(apt)
10+
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getAptEnv(apt) })
11+
updateAptRepos(apt)
12+
}
13+
14+
export async function installAddAptRepo(apt: string) {
15+
if (await isAptPackInstalled("software-properties-common")) {
16+
return
17+
}
18+
execRootSync(
19+
apt,
20+
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
21+
{ ...defaultExecOptions, env: getAptEnv(apt) },
22+
)
23+
}

packages/setup-apt/src/apt-timeout.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* The timeout to use for apt commands
3+
* Wait up to 300 seconds if the apt-get lock is held
4+
* @private Used internally
5+
*/
6+
7+
export const aptTimeout = "Dpkg::Lock::Timeout=300"

packages/setup-apt/src/get-apt.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import which from "which"
2+
3+
/**
4+
* Check if nala is installed
5+
*/
6+
export function hasNala() {
7+
return which.sync("nala", { nothrow: true }) !== null
8+
}
9+
10+
/**
11+
* Get the apt command to use
12+
* If nala is installed, use that, otherwise use apt-get
13+
*/
14+
export function getApt() {
15+
let apt: string
16+
if (hasNala()) {
17+
apt = "nala"
18+
} else {
19+
apt = "apt-get"
20+
}
21+
return apt
22+
}

0 commit comments

Comments
 (0)