Skip to content

Commit ef1ddc1

Browse files
committed
fix!: rename setup-apt functions to include the name apt
1 parent e881f40 commit ef1ddc1

File tree

13 files changed

+49
-28
lines changed

13 files changed

+49
-28
lines changed

dist/actions/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/os-env/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ handles adding conditions to source rc file from .bashrc and .profile
3737

3838
### `escapeString` (function)
3939

40+
Escape a string for use in a shell command
41+
4042
**Parameters:**
4143

42-
- valGiven (`string`)
43-
- shouldEscapeSpace (`boolean`)
44+
- valGiven (`string`) - The string to escape
45+
- shouldEscapeSpace (`boolean`) - Whether to escape spaces in the string
4446

4547
**returns:** any
4648

packages/os-env/src/add-env.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
77
import { escapeString } from "./utils.js"
88
const { appendFile } = promises
99

10+
/**
11+
* The options for adding an environment variable
12+
*/
1013
export type AddEnvOptions = {
1114
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
1215
escapeSpace: boolean

packages/os-env/src/add-path.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { execPowershell } from "exec-powershell"
77
import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
88
const { appendFile } = promises
99

10+
/**
11+
* The options for adding a PATH variable
12+
*/
1013
type AddPathOptions = {
1114
/**
1215
* The path to the RC file that the PATH variables should be added to.

packages/os-env/src/rc-file.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const { appendFile, readFile, writeFile } = promises
88

99
export const defaultRcPath = untildifyUser("~/.bashrc")
1010

11+
/**
12+
* Options for adding an rc file
13+
*/
1114
export type RcOptions = {
1215
/** The path to the RC file that the env variables should be added to. */
1316
rcPath: string

packages/os-env/src/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import escapeSpace from "escape-path-with-spaces"
22
import escapeQuote from "escape-quotes"
33

4+
/**
5+
* Escape a string for use in a shell command
6+
* @param valGiven The string to escape
7+
* @param shouldEscapeSpace Whether to escape spaces in the string
8+
*
9+
* @private
10+
*/
411
export function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
512
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
613
return escapeQuote(spaceEscaped, "\"", "\\")

packages/setup-apt/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Check if a package matching a regexp is installed
6464

6565
**returns:** Promise<boolean>
6666

67-
### `updateRepos` (function)
67+
### `updateAptRepos` (function)
6868

6969
Update the apt repositories
7070

@@ -111,7 +111,7 @@ If nala is installed, use that, otherwise use apt-get
111111

112112
**returns:** string
113113

114-
### `getEnv` (function)
114+
### `getAptEnv` (function)
115115

116116
Get the environment variables to use for the apt command
117117

packages/setup-apt/src/install.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type ExecaError, execa } from "execa"
55
import which from "which"
66
import { addAptKeyViaServer } from "./apt-key.js"
77
import { isAptPackInstalled } from "./is-installed.js"
8-
import { updateRepos } from "./update.js"
8+
import { updateAptRepos } from "./update.js"
99

1010
/**
1111
* The information about an installation result
@@ -63,7 +63,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
6363

6464
// Update the repos if needed
6565
if (update) {
66-
updateRepos(apt)
66+
updateAptRepos(apt)
6767
didUpdate = true
6868
}
6969

@@ -85,15 +85,18 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
8585

8686
// Install
8787
try {
88-
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], { ...defaultExecOptions, env: getEnv(apt) })
88+
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], {
89+
...defaultExecOptions,
90+
env: getAptEnv(apt),
91+
})
8992
} catch (err) {
9093
if (isExecaError(err)) {
9194
if (retryErrors.some((error) => err.stderr.includes(error))) {
9295
warning(`Failed to install packages ${needToInstall}. Retrying...`)
9396
execRootSync(
9497
apt,
9598
["install", "--fix-broken", "-y", "-o", aptTimeout, ...needToInstall],
96-
{ ...defaultExecOptions, env: getEnv(apt) },
99+
{ ...defaultExecOptions, env: getAptEnv(apt) },
97100
)
98101
}
99102
} else {
@@ -134,7 +137,7 @@ export function getApt() {
134137
* @param apt The apt command to use
135138
* @private Used internally
136139
*/
137-
export function getEnv(apt: string) {
140+
export function getAptEnv(apt: string) {
138141
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
139142

140143
if (apt === "nala") {
@@ -185,9 +188,9 @@ async function addRepositories(apt: string, packages: AptPackage[]) {
185188
await installAddAptRepo(apt)
186189
for (const repo of allRepositories) {
187190
// eslint-disable-next-line no-await-in-loop
188-
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getEnv(apt) })
191+
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getAptEnv(apt) })
189192
}
190-
updateRepos(apt)
193+
updateAptRepos(apt)
191194
didUpdate = true
192195
}
193196
}
@@ -198,15 +201,15 @@ async function aptPackageType(apt: string, name: string, version: string | undef
198201
"search",
199202
"--names-only",
200203
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
201-
], { env: getEnv(apt), stdio: "pipe" })
204+
], { env: getAptEnv(apt), stdio: "pipe" })
202205
if (stdout.trim() !== "") {
203206
return AptPackageType.NameDashVersion
204207
}
205208

206209
try {
207210
// check if apt-get show can find the version
208211
// eslint-disable-next-line @typescript-eslint/no-shadow
209-
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getEnv(apt) })
212+
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getAptEnv(apt) })
210213
if (stdout.trim() === "") {
211214
return AptPackageType.NameEqualsVersion
212215
}
@@ -216,7 +219,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
216219
}
217220

218221
try {
219-
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getEnv(apt), stdio: "pipe" })
222+
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getAptEnv(apt), stdio: "pipe" })
220223
if (showStdout.trim() !== "") {
221224
return AptPackageType.Name
222225
}
@@ -226,7 +229,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
226229

227230
// If apt-cache fails, update the repos and try again
228231
if (!didUpdate) {
229-
updateRepos(getApt())
232+
updateAptRepos(getApt())
230233
didUpdate = true
231234
return aptPackageType(apt, name, version)
232235
}
@@ -258,15 +261,15 @@ async function installAddAptRepo(apt: string) {
258261
execRootSync(
259262
apt,
260263
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
261-
{ ...defaultExecOptions, env: getEnv(apt) },
264+
{ ...defaultExecOptions, env: getAptEnv(apt) },
262265
)
263266
}
264267

265268
/** Install gnupg and certificates (usually missing from docker containers) */
266269
async function initApt(apt: string) {
267270
// Update the repos if needed
268271
if (!didUpdate) {
269-
updateRepos(apt)
272+
updateAptRepos(apt)
270273
didUpdate = true
271274
}
272275

@@ -279,7 +282,7 @@ async function initApt(apt: string) {
279282
if (toInstall.length !== 0) {
280283
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, ...toInstall], {
281284
...defaultExecOptions,
282-
env: getEnv(apt),
285+
env: getAptEnv(apt),
283286
})
284287
}
285288

packages/setup-apt/src/is-installed.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execa } from "execa"
2-
import { getEnv } from "./install.js"
2+
import { getAptEnv } from "./install.js"
33

44
/**
55
* Check if a package is installed
@@ -9,7 +9,7 @@ import { getEnv } from "./install.js"
99
export async function isAptPackInstalled(pack: string) {
1010
try {
1111
// check if a package is installed
12-
const { stdout } = await execa("dpkg", ["-s", pack], { env: getEnv("apt-get"), stdio: "pipe" })
12+
const { stdout } = await execa("dpkg", ["-s", pack], { env: getAptEnv("apt-get"), stdio: "pipe" })
1313
if (typeof stdout !== "string") {
1414
return false
1515
}
@@ -29,7 +29,7 @@ export async function isAptPackInstalled(pack: string) {
2929
export async function isAptPackRegexInstalled(regexp: string) {
3030
try {
3131
// check if a package matching the regexp is installed
32-
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getEnv("apt-get"), stdio: "pipe" })
32+
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getAptEnv("apt-get"), stdio: "pipe" })
3333
if (typeof stdout !== "string") {
3434
return false
3535
}

packages/setup-apt/src/update.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { defaultExecOptions, execRootSync } from "admina"
2-
import { aptTimeout, getApt, getEnv } from "./install.js"
2+
import { aptTimeout, getApt, getAptEnv } from "./install.js"
33

44
/**
55
* Update the apt repositories
66
* @param apt The apt command to use (optional)
77
*/
8-
export function updateRepos(apt: string = getApt()) {
8+
export function updateAptRepos(apt: string = getApt()) {
99
execRootSync(
1010
apt,
1111
apt !== "nala" ? ["update", "-y", "-o", aptTimeout] : ["update", "-o", aptTimeout],
12-
{ ...defaultExecOptions, env: getEnv(apt) },
12+
{ ...defaultExecOptions, env: getAptEnv(apt) },
1313
)
1414
}

packages/untildify-user/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Replaces a tilde with the user's home directory
3333
**returns:** string
3434

3535
```tsx
36-
UntildifyUser("~/foo") // /home/user/foo
36+
UntildifyUser('~/foo'); // /home/user/foo
3737
```
3838

3939
<!-- INSERT GENERATED DOCS END -->

0 commit comments

Comments
 (0)