fix: fix the brew installation on Linux

This commit is contained in:
Amin Yahyaabadi 2022-11-20 19:58:50 -08:00
parent 45d9ac5ca2
commit 3ba3a1b365
6 changed files with 29 additions and 8 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

View File

@ -7,7 +7,7 @@ describe("setup-brew", () => {
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
return return
} }
const installInfo = setupBrew("", "", process.arch) const installInfo = await setupBrew("", "", process.arch)
await testBin("brew", ["--version"], installInfo?.binDir) await testBin("brew", ["--version"], installInfo?.binDir)
}) })
}) })

View File

@ -1,11 +1,15 @@
import { execFileSync } from "child_process" import execa from "execa"
import { dirname } from "patha" import { dirname } from "patha"
import which from "which" import which from "which"
import { tmpdir } from "os"
import path, { join } from "path"
import { mkdirP } from "@actions/io"
import { readFileSync } from "fs"
let binDir: string | undefined let binDir: string | undefined
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupBrew(_version: string, _setupDir: string, _arch: string) { export async function setupBrew(_version: string, _setupDir: string, _arch: string) {
if (!["darwin", "linux"].includes(process.platform)) { if (!["darwin", "linux"].includes(process.platform)) {
return undefined return undefined
} }
@ -20,8 +24,25 @@ export function setupBrew(_version: string, _setupDir: string, _arch: string) {
} }
// brew is not thread-safe // brew is not thread-safe
execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, { const brewTempDirectory = path.join(tmpdir(), "setup_cpp", "brew")
await mkdirP(brewTempDirectory)
execa.sync("curl", ["-LJO", "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"], {
cwd: brewTempDirectory,
})
const installSh = join(brewTempDirectory, "install.sh")
if (process.platform === "linux") {
const installShContent = readFileSync(installSh, "utf-8")
installShContent.replace("#!/bin/bash", "")
}
execa.sync("/bin/bash", [installSh], {
stdio: "inherit", stdio: "inherit",
env: {
NONINTERACTIVE: "1",
},
}) })
binDir = "/usr/local/bin/" binDir = "/usr/local/bin/"