fix: use node-download-helper instead of actions/http-client and curl

This commit is contained in:
Amin Yahyaabadi 2024-08-18 01:53:22 -07:00
parent a247573c5d
commit ee265991bc
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
12 changed files with 155 additions and 138 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:*", "untildify-user": "workspace:*",
"util.types": "^0.0.2", "util.types": "^0.0.2",
"web-streams-polyfill": "^4.0.0", "web-streams-polyfill": "^4.0.0",
"which": "^4.0.0" "which": "^4.0.0",
"node-downloader-helper": "2.1.9"
}, },
"productionDependencies": [ "productionDependencies": [
"@actions/core", "@actions/core",
@ -148,6 +149,7 @@
"micro-memoize", "micro-memoize",
"mri", "mri",
"msvc-dev-cmd", "msvc-dev-cmd",
"node-downloader-helper",
"numerous", "numerous",
"envosman", "envosman",
"path-exists", "path-exists",

View File

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

View File

@ -1,8 +1,8 @@
import { tmpdir } from "os"
import { execRoot, execRootSync } from "admina" import { execRoot, execRootSync } from "admina"
import { warning } from "ci-log" import { warning } from "ci-log"
import { execa } from "execa" import { DownloaderHelper } from "node-downloader-helper"
import { pathExists } from "path-exists" import { pathExists } from "path-exists"
import { installAptPack } from "./install.js"
function initGpg() { function initGpg() {
execRootSync("gpg", ["-k"]) execRootSync("gpg", ["-k"])
@ -53,8 +53,13 @@ export async function addAptKeyViaDownload(name: string, url: string) {
const fileName = `/etc/apt/trusted.gpg.d/${name}` const fileName = `/etc/apt/trusted.gpg.d/${name}`
if (!(await pathExists(fileName))) { if (!(await pathExists(fileName))) {
initGpg() initGpg()
await installAptPack([{ name: "curl" }, { name: "ca-certificates" }], undefined)
await execa("curl", ["-s", url, "-o", `/tmp/${name}`]) 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("gpg", ["--no-default-keyring", "--keyring", `gnupg-ring:${fileName}`, "--import", `/tmp/${name}`])
execRootSync("chmod", ["644", fileName]) execRootSync("chmod", ["644", fileName])
} }

View File

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

View File

@ -1,9 +1,7 @@
import { tmpdir } from "os" import { tmpdir } from "os"
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 { DownloaderHelper } from "node-downloader-helper"
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"
@ -31,18 +29,16 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
} }
// download the installation script // download the installation script
const installerPath = join(tmpdir(), "install-brew.sh") const dl = new DownloaderHelper("https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh", tmpdir(), {
fileName: "install-brew.sh",
const http = new HttpClient("setup-brew") })
const response = await http.get("https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh") dl.on("error", (err) => {
if (response.message.statusCode !== 200) { throw new Error(`Failed to download the brew installer script: ${err}`)
throw new Error(`Failed to download brew installation script: ${response.message.statusCode}`) })
} await dl.start()
await writeFile(installerPath, await response.readBody())
// brew installation is not thread-safe // brew installation is not thread-safe
execaSync("/bin/bash", [installerPath], { execaSync("/bin/bash", [dl.getDownloadPath()], {
stdio: "inherit", stdio: "inherit",
env: { env: {
NONINTERACTIVE: "1", NONINTERACTIVE: "1",

View File

@ -1,10 +1,10 @@
import { info } from "console" import { info } from "console"
import { tmpdir } from "os" import { tmpdir } from "os"
import { join } from "path" 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 { chmod, writeFile } from "fs/promises" import { chmod, readFile, writeFile } from "fs/promises"
import { DownloaderHelper } from "node-downloader-helper"
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"
@ -24,12 +24,12 @@ export async function setupLLVMApt(
const installationFolder = `/usr/lib/llvm-${majorVersion}` const installationFolder = `/usr/lib/llvm-${majorVersion}`
// download the installation script // download the installation script
const http = new HttpClient("setup-llvm") const dl = new DownloaderHelper("https://apt.llvm.org/llvm.sh", tmpdir(), { fileName: "llvm.sh" })
const response = await http.get("https://apt.llvm.org/llvm.sh") dl.on("error", (err) => {
if (response.message.statusCode !== 200) { throw new Error(`Failed to download the LLVM installer script: ${err}`)
throw new Error(`Failed to download LLVM installation script: ${response.message.statusCode}`) })
} await dl.start()
const installerScript = await response.readBody() const installerScript = await readFile(dl.getDownloadPath(), "utf-8")
const installerPath = join(tmpdir(), "llvm-setup-cpp.sh") const installerPath = join(tmpdir(), "llvm-setup-cpp.sh")
const neededPackages = await patchAptLLVMScript( const neededPackages = await patchAptLLVMScript(