Merge pull request #262 from aminya/downloader [skip ci]

This commit is contained in:
Amin Yahyaabadi 2024-08-19 01:39:57 -07:00 committed by GitHub
commit 42d0df7db6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 201 additions and 145 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

@ -126,7 +126,8 @@
"untildify-user": "workspace:*",
"util.types": "^0.0.2",
"web-streams-polyfill": "^4.0.0",
"which": "^4.0.0"
"which": "^4.0.0",
"node-downloader-helper": "2.1.9"
},
"productionDependencies": [
"@actions/core",
@ -148,6 +149,7 @@
"micro-memoize",
"mri",
"msvc-dev-cmd",
"node-downloader-helper",
"numerous",
"envosman",
"path-exists",

View File

@ -23,7 +23,8 @@
"envosman": "workspace:*",
"which": "4.0.0",
"execa": "^7.2.0",
"escape-string-regexp": "^5.0.0"
"escape-string-regexp": "^5.0.0",
"node-downloader-helper": "2.1.9"
},
"engines": {
"node": ">=12"

View File

@ -1,6 +1,7 @@
import { tmpdir } from "os"
import { execRoot, execRootSync } from "admina"
import { warning } from "ci-log"
import { execa } from "execa"
import { DownloaderHelper } from "node-downloader-helper"
import { pathExists } from "path-exists"
import { installAptPack } from "./install.js"
@ -53,8 +54,14 @@ export async function addAptKeyViaDownload(name: string, url: string) {
const fileName = `/etc/apt/trusted.gpg.d/${name}`
if (!(await pathExists(fileName))) {
initGpg()
await installAptPack([{ name: "curl" }, { name: "ca-certificates" }], undefined)
await execa("curl", ["-s", url, "-o", `/tmp/${name}`])
await installAptPack([{ name: "ca-certificates" }])
const dl = new DownloaderHelper(url, tmpdir(), { fileName: name })
dl.on("error", (err) => {
throw new Error(`Failed to download ${url}: ${err}`)
})
await dl.start()
execRootSync("gpg", ["--no-default-keyring", "--keyring", `gnupg-ring:${fileName}`, "--import", `/tmp/${name}`])
execRootSync("chmod", ["644", fileName])
}

View File

@ -140,6 +140,9 @@ importers:
msvc-dev-cmd:
specifier: github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd
version: https://codeload.github.com/aminya/msvc-dev-cmd/tar.gz/c01f519bd995460228ed3dec4df51df92dc290fd
node-downloader-helper:
specifier: 2.1.9
version: 2.1.9
npm-check-updates:
specifier: ^17.0.6
version: 17.0.6
@ -306,6 +309,9 @@ importers:
execa:
specifier: ^7.2.0
version: 7.2.0
node-downloader-helper:
specifier: 2.1.9
version: 2.1.9
path-exists:
specifier: ^5.0.0
version: 5.0.0
@ -4176,6 +4182,11 @@ packages:
node-addon-api@7.1.1:
resolution: {integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==}
node-downloader-helper@2.1.9:
resolution: {integrity: sha512-FSvAol2Z8UP191sZtsUZwHIN0eGoGue3uEXGdWIH5228e9KH1YHXT7fN8Oa33UGf+FbqGTQg3sJfrRGzmVCaJA==}
engines: {node: '>=14.18'}
hasBin: true
node-fetch@2.7.0:
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
engines: {node: 4.x || >=6.0.0}
@ -10343,6 +10354,8 @@ snapshots:
node-addon-api@7.1.1: {}
node-downloader-helper@2.1.9: {}
node-fetch@2.7.0(encoding@0.1.13):
dependencies:
whatwg-url: 5.0.0

View File

@ -1,10 +1,9 @@
import { tmpdir } from "os"
import path, { join } from "path"
import { mkdirP } from "@actions/io"
import { addPath } from "envosman"
import { execaSync } from "execa"
import { readFile } from "fs/promises"
import { DownloaderHelper } from "node-downloader-helper"
import { dirname } from "patha"
import { installAptPack } from "setup-apt"
import which from "which"
import { rcOptions } from "../cli-options.js"
@ -13,50 +12,66 @@ let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupBrew(_version: string, _setupDir: string, _arch: string) {
// brew is only available on darwin and linux
if (!["darwin", "linux"].includes(process.platform)) {
return undefined
}
// check if the function has already been called
if (typeof binDir === "string") {
return { binDir }
}
const maybeBinDir = which.sync("brew", { nothrow: true })
// check if brew is already installed
const maybeBinDir = await which("brew", { nothrow: true })
if (maybeBinDir !== null) {
binDir = dirname(maybeBinDir)
return { binDir }
}
// brew is not thread-safe
const brewTempDirectory = path.join(tmpdir(), "setup-cpp", "brew")
await mkdirP(brewTempDirectory)
execaSync("curl", ["-LJO", "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"], {
cwd: brewTempDirectory,
// download the installation script
await installAptPack([{ name: "ca-certificates" }])
const dl = new DownloaderHelper("https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh", tmpdir(), {
fileName: "install-brew.sh",
})
const installSh = join(brewTempDirectory, "install.sh")
dl.on("error", (err) => {
throw new Error(`Failed to download the brew installer script: ${err}`)
})
await dl.start()
if (process.platform === "linux") {
const installShContent = await readFile(installSh, "utf-8")
installShContent.replace("#!/bin/bash", "")
}
execaSync("/bin/bash", [installSh], {
// brew installation is not thread-safe
execaSync("/bin/bash", [dl.getDownloadPath()], {
stdio: "inherit",
env: {
NONINTERACTIVE: "1",
},
})
// add the bin directory to the PATH
binDir = getBrewPath()
await addPath(binDir, rcOptions)
return { binDir }
}
/**
* Get the path where brew is installed
* @returns {string} The path where brew is installed
*
* Based on the installation script from https://brew.sh
*/
export function getBrewPath() {
if (process.platform === "linux") {
return "/home/linuxbrew/.linuxbrew/bin/"
if (process.platform === "darwin") {
if (process.arch === "arm64") {
return "/opt/homebrew/bin/"
} else {
return "/usr/local/bin/"
}
}
if (process.platform === "linux") {
return "/home/linuxbrew/.linuxbrew/bin/"
}
throw new Error("Unsupported platform for brew")
}

View File

@ -1,8 +1,10 @@
import { info } from "console"
import { tmpdir } from "os"
import { join } from "path"
import { execRoot } from "admina"
import { addPath } from "envosman"
import { execa } from "execa"
import { chmod, readFile, writeFile } from "fs/promises"
import { DownloaderHelper } from "node-downloader-helper"
import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt"
import { rcOptions } from "../cli-options.js"
import { DEFAULT_TIMEOUT } from "../installTool.js"
@ -21,14 +23,27 @@ export async function setupLLVMApt(
// TODO for older versions, this also includes the minor version
const installationFolder = `/usr/lib/llvm-${majorVersion}`
await installAptPack([{ name: "curl" }])
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh", majorVersion, packages)
// download the installation script
await installAptPack([{ name: "ca-certificates" }])
const dl = new DownloaderHelper("https://apt.llvm.org/llvm.sh", tmpdir(), { fileName: "llvm.sh" })
dl.on("error", (err) => {
throw new Error(`Failed to download the LLVM installer script: ${err}`)
})
await dl.start()
const installerScript = await readFile(dl.getDownloadPath(), "utf-8")
const installerPath = join(tmpdir(), "llvm-setup-cpp.sh")
const neededPackages = await patchAptLLVMScript(
installerScript,
installerPath,
majorVersion,
packages,
)
await installAptPack(neededPackages)
await chmod("/tmp/llvm-setup-cpp.sh", "755")
await chmod(installerPath, "755")
await execRoot(
"bash",
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
[installerPath, `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
{
stdio: "inherit",
shell: true,
@ -45,10 +60,13 @@ export async function setupLLVMApt(
}
}
async function patchAptLLVMScript(path: string, target_path: string, majorVersion: number, packages: LLVMPackages) {
let script = await readFile(path, "utf-8")
script = debugScript(script)
async function patchAptLLVMScript(
givenScript: string,
target_path: string,
majorVersion: number,
packages: LLVMPackages,
) {
let script = debugScript(givenScript)
script = nonInteractiveScript(script)
script = choosePackages(packages, script, majorVersion)
script = await removeConflictingPackages(script)