mirror of https://github.com/aminya/setup-cpp
feat: add setupBrew
This commit is contained in:
parent
1cad859704
commit
7957d7f52a
|
@ -0,0 +1,17 @@
|
||||||
|
import { setupBrew } from "../brew"
|
||||||
|
import { spawnSync as spawn } from "child_process"
|
||||||
|
|
||||||
|
jest.setTimeout(200000)
|
||||||
|
describe("setup-brew", () => {
|
||||||
|
it("should setup brew", async () => {
|
||||||
|
if (process.platform !== "darwin") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await setupBrew()
|
||||||
|
|
||||||
|
const { status } = spawn("brew", ["--version"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
})
|
||||||
|
expect(status).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { exec } from "@actions/exec"
|
||||||
|
import which from "which"
|
||||||
|
|
||||||
|
export async function setupBrew() {
|
||||||
|
if (!["darwin", "linux"].includes(process.platform)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (which.sync("brew", { nothrow: true }) !== null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const exit = await exec(
|
||||||
|
`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
|
||||||
|
)
|
||||||
|
|
||||||
|
if (exit !== 0) {
|
||||||
|
throw new Error(`Failed to install brew`)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
|
import { setupBrew } from "./brew/brew"
|
||||||
import { setupChocolatey } from "./chocolatey/chocolatey"
|
import { setupChocolatey } from "./chocolatey/chocolatey"
|
||||||
import { setupCmake } from "./cmake/cmake"
|
import { setupCmake } from "./cmake/cmake"
|
||||||
import { setupConan } from "./conan/conan"
|
import { setupConan } from "./conan/conan"
|
||||||
|
@ -69,6 +70,12 @@ export async function main(): Promise<number> {
|
||||||
await setupChocolatey()
|
await setupChocolatey()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup brew
|
||||||
|
const brewVersion = maybeGetInput("brew")
|
||||||
|
if (brewVersion !== undefined) {
|
||||||
|
await setupBrew()
|
||||||
|
}
|
||||||
|
|
||||||
// setup msvc
|
// setup msvc
|
||||||
const msvcVersion = maybeGetInput("msvc")
|
const msvcVersion = maybeGetInput("msvc")
|
||||||
if (msvcVersion !== undefined) {
|
if (msvcVersion !== undefined) {
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
/* eslint-disable require-atomic-updates */
|
/* eslint-disable require-atomic-updates */
|
||||||
import { exec } from "@actions/exec"
|
import { exec } from "@actions/exec"
|
||||||
|
import which from "which"
|
||||||
|
import { setupBrew } from "../../brew/brew"
|
||||||
|
|
||||||
|
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 async function setupBrewPack(name: string, version?: string) {
|
||||||
|
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
||||||
|
await setupBrew()
|
||||||
|
hasBrew = true
|
||||||
|
}
|
||||||
|
|
||||||
const exit = await exec("brew", ["install", version !== undefined ? `${name}@${version}` : name])
|
const exit = await exec("brew", ["install", version !== undefined ? `${name}@${version}` : name])
|
||||||
|
|
||||||
if (exit !== 0) {
|
if (exit !== 0) {
|
||||||
|
|
Loading…
Reference in New Issue