Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add overwrite option for brew + enabled by default #263

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package-lock=false
lockfile=true
public-hoist-pattern=['*eslint*', '*prettier*', '*@types*']
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ words:
- iarna
- cobertura
- copr
- pnpx
- CPATH
- Cppcheck
- CPPFLAGS
Expand Down
1 change: 0 additions & 1 deletion dist/actions/actions_python.60e051e1.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/actions/actions_python.efec3a8c.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/actions/hdi.647acde1.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions dist/modern/hdi.647acde1.js → dist/actions/hdi.7a328924.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/actions/hdi.7a328924.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/legacy/actions_python.11da06c9.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/legacy/actions_python.895b8a50.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/legacy/hdi.619de66c.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions dist/legacy/hdi.619de66c.js → dist/legacy/hdi.dcf7929b.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/legacy/hdi.dcf7929b.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/modern/actions_python.60e051e1.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/actions_python.efec3a8c.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/modern/hdi.647acde1.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions dist/actions/hdi.647acde1.js → dist/modern/hdi.7a328924.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/hdi.7a328924.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"numerous": "1.0.3",
"envosman": "workspace:*",
"p-timeout": "^6.1.2",
"parcel": "2.12.0",
"parcel": "2.0.0-canary.1717",
"path-exists": "^5.0.0",
"patha": "^0.4.1",
"prettier": "3.2.2",
Expand Down
840 changes: 423 additions & 417 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/brew/brew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
})

// add the bin directory to the PATH
binDir = getBrewPath()
binDir = getBrewBinDir()
await addPath(binDir, rcOptions)

return { binDir }
Expand All @@ -60,7 +60,7 @@ export async function setupBrew(_version: string, _setupDir: string, _arch: stri
*
* Based on the installation script from https://brew.sh
*/
export function getBrewPath() {
export function getBrewBinDir() {
if (process.platform === "darwin") {
if (process.arch === "arm64") {
return "/opt/homebrew/bin/"
Expand Down
2 changes: 1 addition & 1 deletion src/powershell/powershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
return { binDir }
}
case "darwin": {
return setupBrewPack("powershell", version, ["--cask"])
return setupBrewPack("powershell", version, { cask: true, overwrite: false })
}
case "linux": {
if (isArch()) {
Expand Down
43 changes: 33 additions & 10 deletions src/utils/setup/setupBrewPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,57 @@ import { info } from "@actions/core"
import { execaSync } from "execa"
import { join } from "patha"
import which from "which"
import { getBrewPath, setupBrew } from "../../brew/brew.js"
import { getBrewBinDir, setupBrew } from "../../brew/brew.js"
import type { InstallationInfo } from "./setupBin.js"

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 */
export async function setupBrewPack(
name: string,
version?: string,
extraArgs: string[] = [],
givenOptions: BrewPackOptions = {},
): Promise<InstallationInfo> {
const options = {
overwrite: true,
cask: false,
args: [],
...givenOptions,
}

info(`Installing ${name} ${version ?? ""} via brew`)

if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
await setupBrew("", "", process.arch)
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
execaSync(
join(binDir, "brew"),
["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs],
{
stdio: "inherit",
},
)
execaSync(brewPath, args, { stdio: "inherit" })

return { binDir }
}
Loading