Skip to content

Commit a247573

Browse files
committed
fix: use http client for downloading the LLVM installer
1 parent 1a9cdb3 commit a247573

File tree

8 files changed

+42
-25
lines changed

8 files changed

+42
-25
lines changed

dist/actions/setup-cpp.js

Lines changed: 3 additions & 3 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: 3 additions & 3 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: 3 additions & 3 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.

src/brew/brew.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { tmpdir } from "os"
22
import { join } from "path"
3+
import { HttpClient } from "@actions/http-client"
34
import { addPath } from "envosman"
45
import { execaSync } from "execa"
6+
import { writeFile } from "fs/promises"
57
import { dirname } from "patha"
68
import which from "which"
79
import { rcOptions } from "../cli-options.js"
8-
import { HttpClient } from "@actions/http-client"
9-
import { writeFile } from "fs/promises"
1010

1111
/* eslint-disable require-atomic-updates */
1212
let binDir: string | undefined

src/llvm/llvm_installer.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { info } from "console"
2+
import { tmpdir } from "os"
3+
import { join } from "path"
4+
import { HttpClient } from "@actions/http-client"
25
import { execRoot } from "admina"
36
import { addPath } from "envosman"
4-
import { execa } from "execa"
5-
import { chmod, readFile, writeFile } from "fs/promises"
7+
import { chmod, writeFile } from "fs/promises"
68
import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt"
79
import { rcOptions } from "../cli-options.js"
810
import { DEFAULT_TIMEOUT } from "../installTool.js"
@@ -21,14 +23,26 @@ export async function setupLLVMApt(
2123
// TODO for older versions, this also includes the minor version
2224
const installationFolder = `/usr/lib/llvm-${majorVersion}`
2325

24-
await installAptPack([{ name: "curl" }])
25-
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
26-
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh", majorVersion, packages)
26+
// download the installation script
27+
const http = new HttpClient("setup-llvm")
28+
const response = await http.get("https://apt.llvm.org/llvm.sh")
29+
if (response.message.statusCode !== 200) {
30+
throw new Error(`Failed to download LLVM installation script: ${response.message.statusCode}`)
31+
}
32+
const installerScript = await response.readBody()
33+
34+
const installerPath = join(tmpdir(), "llvm-setup-cpp.sh")
35+
const neededPackages = await patchAptLLVMScript(
36+
installerScript,
37+
installerPath,
38+
majorVersion,
39+
packages,
40+
)
2741
await installAptPack(neededPackages)
28-
await chmod("/tmp/llvm-setup-cpp.sh", "755")
42+
await chmod(installerPath, "755")
2943
await execRoot(
3044
"bash",
31-
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
45+
[installerPath, `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
3246
{
3347
stdio: "inherit",
3448
shell: true,
@@ -45,10 +59,13 @@ export async function setupLLVMApt(
4559
}
4660
}
4761

48-
async function patchAptLLVMScript(path: string, target_path: string, majorVersion: number, packages: LLVMPackages) {
49-
let script = await readFile(path, "utf-8")
50-
51-
script = debugScript(script)
62+
async function patchAptLLVMScript(
63+
givenScript: string,
64+
target_path: string,
65+
majorVersion: number,
66+
packages: LLVMPackages,
67+
) {
68+
let script = debugScript(givenScript)
5269
script = nonInteractiveScript(script)
5370
script = choosePackages(packages, script, majorVersion)
5471
script = await removeConflictingPackages(script)

0 commit comments

Comments
 (0)