Skip to content

Commit 1c89539

Browse files
committed
fix: handle no update failures for llvm
1 parent b32feb0 commit 1c89539

File tree

10 files changed

+51
-28
lines changed

10 files changed

+51
-28
lines changed

dist/legacy/assets/actions_python-cP6XyATB.js renamed to dist/legacy/assets/actions_python-B0F8mOt1.js

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

dist/legacy/assets/actions_python-cP6XyATB.js.map renamed to dist/legacy/assets/actions_python-B0F8mOt1.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: 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.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.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.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/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-apt",
3-
"version": "3.1.2",
3+
"version": "3.1.3",
44
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
55
"repository": "https://github.com/aminya/setup-cpp",
66
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @private Used internally
55
*/
66

7-
export function getAptEnv(apt: string) {
7+
export function getAptEnv(apt: string = "apt-get") {
88
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
99

1010
if (apt === "nala") {

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,38 @@ import { initAptMemoized } from "./init-apt.js"
77
import { isAptPackInstalled } from "./is-installed.js"
88
import { updateAptReposMemoized } from "./update.js"
99

10-
function hasNoUpdateFlag_(apt: string) {
11-
const { stdout } = execRootSync("add-apt-repository", ["--help"], {
12-
...defaultExecOptions,
13-
env: getAptEnv(apt),
14-
stdio: "pipe",
15-
})
16-
return stdout.includes("--no-update")
10+
function hasNoUpdateFlag_(apt: string = "apt-get") {
11+
try {
12+
const { stdout } = execRootSync("add-apt-repository", ["--help"], {
13+
...defaultExecOptions,
14+
env: getAptEnv(apt),
15+
stdio: "pipe",
16+
})
17+
return stdout.includes("--no-update")
18+
} catch (err) {
19+
return false
20+
}
1721
}
18-
const hasNoUpdateFlag = memoize(hasNoUpdateFlag_)
22+
export const addAptHasNoUpdateFlag = memoize(hasNoUpdateFlag_)
1923

2024
export async function addAptRepository(repo: string, apt = getApt()) {
2125
await initAptMemoized(apt)
2226
await installAddAptRepo()
23-
execRootSync(
24-
"add-apt-repository",
25-
["-y", hasNoUpdateFlag(apt) ? "--no-update" : undefined, repo].filter(a => a !== undefined),
26-
{ ...defaultExecOptions, env: getAptEnv(apt) },
27-
)
27+
28+
try {
29+
execRootSync(
30+
"add-apt-repository",
31+
["-y", addAptHasNoUpdateFlag(apt) ? "--no-update" : undefined, repo].filter(a => a !== undefined),
32+
{ ...defaultExecOptions, env: getAptEnv(apt) },
33+
)
34+
} catch (err) {
35+
// try without the no-update flag
36+
execRootSync(
37+
"add-apt-repository",
38+
["-y", repo],
39+
{ ...defaultExecOptions, env: getAptEnv(apt) },
40+
)
41+
}
2842

2943
// Update the repos
3044
updateAptReposMemoized.clear() // ensure update is called
@@ -48,7 +62,7 @@ export async function removeAptRepository(repo: string, apt = getApt()) {
4862
await installAddAptRepo()
4963
execRootSync(
5064
"add-apt-repository",
51-
["-y", "--remove", hasNoUpdateFlag(apt) ? undefined : "--no-update", repo].filter(a => a !== undefined),
65+
["-y", "--remove", addAptHasNoUpdateFlag(apt) ? undefined : "--no-update", repo].filter(a => a !== undefined),
5266
{ ...defaultExecOptions, env: getAptEnv(apt) },
5367
)
5468

src/llvm/llvm_apt_installer.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import { execRoot, execRootSync } from "admina"
66
import { addPath } from "envosman"
77
import { chmod, readFile, writeFile } from "fs/promises"
88
import { DownloaderHelper } from "node-downloader-helper"
9-
import { aptTimeout, hasAptGet, hasNala, installAddAptRepo, installAptPack, isAptPackRegexInstalled } from "setup-apt"
9+
import {
10+
addAptHasNoUpdateFlag,
11+
aptTimeout,
12+
hasAptGet,
13+
hasNala,
14+
installAddAptRepo,
15+
installAptPack,
16+
isAptPackRegexInstalled,
17+
} from "setup-apt"
1018
import { DEFAULT_TIMEOUT } from "../installTool.js"
1119
import { rcOptions } from "../options.js"
1220
import type { InstallationInfo } from "../utils/setup/setupBin.js"
@@ -70,7 +78,7 @@ export async function setupLLVMApt(
7078

7179
// download the installation script
7280
await installAptPack([{ name: "ca-certificates" }])
73-
const dl = new DownloaderHelper("https://apt.llvm.org/llvm.sh", tmpdir(), { fileName: "llvm.sh" })
81+
const dl = new DownloaderHelper("https://apt.llvm.org/llvm.sh", tmpdir(), { fileName: "llvm.sh", override: true })
7482
dl.on("error", (err) => {
7583
throw new Error(`Failed to download the LLVM installer script: ${err}`)
7684
})
@@ -116,7 +124,7 @@ async function patchAptLLVMScript(
116124
script = nonInteractiveScript(script)
117125
script = choosePackages(packages, script, majorVersion)
118126
script = await removeConflictingPackages(script)
119-
script = useNalaScript(script)
127+
script = mayUseNalaScript(script)
120128

121129
await writeFile(target_path, script)
122130
}
@@ -130,9 +138,10 @@ function debugScript(script: string) {
130138

131139
function nonInteractiveScript(script: string) {
132140
// make the scirpt non-interactive and fix broken packages
141+
const hasNoUpdate = addAptHasNoUpdateFlag()
133142
return script.replace(
134143
/add-apt-repository\s*(-y)?\s*"\${REPO_NAME}"/g,
135-
`add-apt-repository -y "\${REPO_NAME}"
144+
`add-apt-repository -y ${hasNoUpdate ? "--no-update" : ""} "\${REPO_NAME}"
136145
apt-get update -o ${aptTimeout}`,
137146
)
138147
}
@@ -158,7 +167,7 @@ async function removeConflictingPackages(givenScript: string) {
158167
return script
159168
}
160169

161-
function useNalaScript(script: string) {
170+
function mayUseNalaScript(script: string) {
162171
// use nala if it is available
163172
if (hasNala()) {
164173
return script.replace(/apt-get/g, "nala")

0 commit comments

Comments
 (0)