Skip to content

Commit 89ba83d

Browse files
committed
feat: add overwrite option for brew + enabled by default
1 parent 42d0df7 commit 89ba83d

File tree

9 files changed

+45
-22
lines changed

9 files changed

+45
-22
lines changed

dist/actions/setup-cpp.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/brew/brew.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
4848
})
4949

5050
// add the bin directory to the PATH
51-
binDir = getBrewPath()
51+
binDir = getBrewBinDir()
5252
await addPath(binDir, rcOptions)
5353

5454
return { binDir }
@@ -60,7 +60,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
6060
*
6161
* Based on the installation script from https://brew.sh
6262
*/
63-
export function getBrewPath() {
63+
export function getBrewBinDir() {
6464
if (process.platform === "darwin") {
6565
if (process.arch === "arm64") {
6666
return "/opt/homebrew/bin/"

src/powershell/powershell.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
2121
return { binDir }
2222
}
2323
case "darwin": {
24-
return setupBrewPack("powershell", version, ["--cask"])
24+
return setupBrewPack("powershell", version, { cask: true })
2525
}
2626
case "linux": {
2727
if (isArch()) {

src/utils/setup/setupBrewPack.ts

+33-10
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,57 @@ import { info } from "@actions/core"
33
import { execaSync } from "execa"
44
import { join } from "patha"
55
import which from "which"
6-
import { getBrewPath, setupBrew } from "../../brew/brew.js"
6+
import { getBrewBinDir, setupBrew } from "../../brew/brew.js"
77
import type { InstallationInfo } from "./setupBin.js"
88

99
let hasBrew = false
1010

11+
type BrewPackOptions = {
12+
/** Whether to overwrite the package if it already exists */
13+
overwrite?: boolean
14+
/** Whether to install the package as a cask */
15+
cask?: boolean
16+
/** Extra args */
17+
args?: string[]
18+
}
19+
1120
/** A function that installs a package using brew */
1221
export async function setupBrewPack(
1322
name: string,
1423
version?: string,
15-
extraArgs: string[] = [],
24+
givenOptions: BrewPackOptions = {},
1625
): Promise<InstallationInfo> {
26+
const options = {
27+
overwrite: false,
28+
cask: false,
29+
args: [],
30+
...givenOptions,
31+
}
32+
1733
info(`Installing ${name} ${version ?? ""} via brew`)
1834

1935
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
2036
await setupBrew("", "", process.arch)
2137
hasBrew = true
2238
}
2339

24-
const binDir = getBrewPath()
40+
const binDir = getBrewBinDir()
41+
const brewPath = join(binDir, "brew")
42+
43+
// Args
44+
const args = [
45+
"install",
46+
(version !== undefined && version !== "") ? `${name}@${version}` : name,
47+
]
48+
if (options.overwrite) {
49+
args.push("--overwrite")
50+
}
51+
if (options.cask) {
52+
args.push("--cask")
53+
}
2554

2655
// brew is not thread-safe
27-
execaSync(
28-
join(binDir, "brew"),
29-
["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs],
30-
{
31-
stdio: "inherit",
32-
},
33-
)
56+
execaSync(brewPath, args, { stdio: "inherit" })
3457

3558
return { binDir }
3659
}

0 commit comments

Comments
 (0)