fix: use http client for downloading the LLVM installer

This commit is contained in:
Amin Yahyaabadi 2024-08-16 23:24:57 -07:00
parent 1a9cdb35d8
commit a247573c5d
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
8 changed files with 42 additions and 25 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,12 @@
import { tmpdir } from "os" import { tmpdir } from "os"
import { join } from "path" import { join } from "path"
import { HttpClient } from "@actions/http-client"
import { addPath } from "envosman" import { addPath } from "envosman"
import { execaSync } from "execa" import { execaSync } from "execa"
import { writeFile } from "fs/promises"
import { dirname } from "patha" import { dirname } from "patha"
import which from "which" import which from "which"
import { rcOptions } from "../cli-options.js" import { rcOptions } from "../cli-options.js"
import { HttpClient } from "@actions/http-client"
import { writeFile } from "fs/promises"
/* eslint-disable require-atomic-updates */ /* eslint-disable require-atomic-updates */
let binDir: string | undefined let binDir: string | undefined

View File

@ -1,8 +1,10 @@
import { info } from "console" import { info } from "console"
import { tmpdir } from "os"
import { join } from "path"
import { HttpClient } from "@actions/http-client"
import { execRoot } from "admina" import { execRoot } from "admina"
import { addPath } from "envosman" import { addPath } from "envosman"
import { execa } from "execa" import { chmod, writeFile } from "fs/promises"
import { chmod, readFile, writeFile } from "fs/promises"
import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt" import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt"
import { rcOptions } from "../cli-options.js" import { rcOptions } from "../cli-options.js"
import { DEFAULT_TIMEOUT } from "../installTool.js" import { DEFAULT_TIMEOUT } from "../installTool.js"
@ -21,14 +23,26 @@ export async function setupLLVMApt(
// TODO for older versions, this also includes the minor version // TODO for older versions, this also includes the minor version
const installationFolder = `/usr/lib/llvm-${majorVersion}` const installationFolder = `/usr/lib/llvm-${majorVersion}`
await installAptPack([{ name: "curl" }]) // download the installation script
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" }) const http = new HttpClient("setup-llvm")
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh", majorVersion, packages) const response = await http.get("https://apt.llvm.org/llvm.sh")
if (response.message.statusCode !== 200) {
throw new Error(`Failed to download LLVM installation script: ${response.message.statusCode}`)
}
const installerScript = await response.readBody()
const installerPath = join(tmpdir(), "llvm-setup-cpp.sh")
const neededPackages = await patchAptLLVMScript(
installerScript,
installerPath,
majorVersion,
packages,
)
await installAptPack(neededPackages) await installAptPack(neededPackages)
await chmod("/tmp/llvm-setup-cpp.sh", "755") await chmod(installerPath, "755")
await execRoot( await execRoot(
"bash", "bash",
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])], [installerPath, `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
{ {
stdio: "inherit", stdio: "inherit",
shell: true, shell: true,
@ -45,10 +59,13 @@ export async function setupLLVMApt(
} }
} }
async function patchAptLLVMScript(path: string, target_path: string, majorVersion: number, packages: LLVMPackages) { async function patchAptLLVMScript(
let script = await readFile(path, "utf-8") givenScript: string,
target_path: string,
script = debugScript(script) majorVersion: number,
packages: LLVMPackages,
) {
let script = debugScript(givenScript)
script = nonInteractiveScript(script) script = nonInteractiveScript(script)
script = choosePackages(packages, script, majorVersion) script = choosePackages(packages, script, majorVersion)
script = await removeConflictingPackages(script) script = await removeConflictingPackages(script)