fix: install brew synchronously

This commit is contained in:
Amin Yahyaabadi 2021-09-16 04:28:33 -05:00
parent eaec708616
commit 841f079886
2 changed files with 8 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import { exec } from "@actions/exec" import { execFileSync } from "child_process"
import which from "which" import which from "which"
export async function setupBrew() { export function setupBrew() {
if (!["darwin", "linux"].includes(process.platform)) { if (!["darwin", "linux"].includes(process.platform)) {
return return
} }
@ -10,11 +10,8 @@ export async function setupBrew() {
return return
} }
const exit = await exec( // brew is not thread-safe
`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` execFileSync(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`, {
) stdio: "inherit",
})
if (exit !== 0) {
throw new Error(`Failed to install brew`)
}
} }

View File

@ -6,9 +6,9 @@ import { setupBrew } from "../../brew/brew"
let hasBrew = false let hasBrew = false
/** A function that installs a package using brew */ /** A function that installs a package using brew */
export async function setupBrewPack(name: string, version?: string) { export function setupBrewPack(name: string, version?: string) {
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) { if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
await setupBrew() setupBrew()
hasBrew = true hasBrew = true
} }