mirror of https://github.com/aminya/setup-cpp
feat: add overwrite option for brew + enabled by default
Update setupBrewPack.ts
This commit is contained in:
parent
42d0df7db6
commit
b7b6d75da7
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
|
@ -48,7 +48,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
|
||||||
})
|
})
|
||||||
|
|
||||||
// add the bin directory to the PATH
|
// add the bin directory to the PATH
|
||||||
binDir = getBrewPath()
|
binDir = getBrewBinDir()
|
||||||
await addPath(binDir, rcOptions)
|
await addPath(binDir, rcOptions)
|
||||||
|
|
||||||
return { binDir }
|
return { binDir }
|
||||||
|
@ -60,7 +60,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
|
||||||
*
|
*
|
||||||
* Based on the installation script from https://brew.sh
|
* Based on the installation script from https://brew.sh
|
||||||
*/
|
*/
|
||||||
export function getBrewPath() {
|
export function getBrewBinDir() {
|
||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
if (process.arch === "arm64") {
|
if (process.arch === "arm64") {
|
||||||
return "/opt/homebrew/bin/"
|
return "/opt/homebrew/bin/"
|
||||||
|
|
|
@ -21,7 +21,7 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
case "darwin": {
|
case "darwin": {
|
||||||
return setupBrewPack("powershell", version, ["--cask"])
|
return setupBrewPack("powershell", version, { cask: true })
|
||||||
}
|
}
|
||||||
case "linux": {
|
case "linux": {
|
||||||
if (isArch()) {
|
if (isArch()) {
|
||||||
|
|
|
@ -3,17 +3,33 @@ import { info } from "@actions/core"
|
||||||
import { execaSync } from "execa"
|
import { execaSync } from "execa"
|
||||||
import { join } from "patha"
|
import { join } from "patha"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { getBrewPath, setupBrew } from "../../brew/brew.js"
|
import { getBrewBinDir, setupBrew } from "../../brew/brew.js"
|
||||||
import type { InstallationInfo } from "./setupBin.js"
|
import type { InstallationInfo } from "./setupBin.js"
|
||||||
|
|
||||||
let hasBrew = false
|
let hasBrew = false
|
||||||
|
|
||||||
|
type BrewPackOptions = {
|
||||||
|
/** Whether to overwrite the package if it already exists */
|
||||||
|
overwrite?: boolean
|
||||||
|
/** Whether to install the package as a cask */
|
||||||
|
cask?: boolean
|
||||||
|
/** Extra args */
|
||||||
|
args?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
/** A function that installs a package using brew */
|
/** A function that installs a package using brew */
|
||||||
export async function setupBrewPack(
|
export async function setupBrewPack(
|
||||||
name: string,
|
name: string,
|
||||||
version?: string,
|
version?: string,
|
||||||
extraArgs: string[] = [],
|
givenOptions: BrewPackOptions = {},
|
||||||
): Promise<InstallationInfo> {
|
): Promise<InstallationInfo> {
|
||||||
|
const options = {
|
||||||
|
overwrite: true,
|
||||||
|
cask: false,
|
||||||
|
args: [],
|
||||||
|
...givenOptions,
|
||||||
|
}
|
||||||
|
|
||||||
info(`Installing ${name} ${version ?? ""} via brew`)
|
info(`Installing ${name} ${version ?? ""} via brew`)
|
||||||
|
|
||||||
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
||||||
|
@ -21,16 +37,23 @@ export async function setupBrewPack(
|
||||||
hasBrew = true
|
hasBrew = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const binDir = getBrewPath()
|
const binDir = getBrewBinDir()
|
||||||
|
const brewPath = join(binDir, "brew")
|
||||||
|
|
||||||
|
// Args
|
||||||
|
const args = [
|
||||||
|
"install",
|
||||||
|
(version !== undefined && version !== "") ? `${name}@${version}` : name,
|
||||||
|
]
|
||||||
|
if (options.overwrite) {
|
||||||
|
args.push("--overwrite")
|
||||||
|
}
|
||||||
|
if (options.cask) {
|
||||||
|
args.push("--cask")
|
||||||
|
}
|
||||||
|
|
||||||
// brew is not thread-safe
|
// brew is not thread-safe
|
||||||
execaSync(
|
execaSync(brewPath, args, { stdio: "inherit" })
|
||||||
join(binDir, "brew"),
|
|
||||||
["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs],
|
|
||||||
{
|
|
||||||
stdio: "inherit",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue