Merge pull request #263 from aminya/brew-overwrite [skip ci]

This commit is contained in:
Amin Yahyaabadi 2024-08-20 16:06:36 -07:00 committed by GitHub
commit 35ec48abe6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 493 additions and 462 deletions

1
.npmrc
View File

@ -1,2 +1,3 @@
package-lock=false
lockfile=true
public-hoist-pattern=['*eslint*', '*prettier*', '*@types*']

View File

@ -29,6 +29,7 @@ words:
- iarna
- cobertura
- copr
- pnpx
- CPATH
- Cppcheck
- CPPFLAGS

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

1
dist/actions/hdi.7a328924.js.map vendored Normal file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
dist/legacy/hdi.dcf7929b.js.map vendored Normal file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
dist/modern/hdi.7a328924.js.map vendored Normal file

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

View File

@ -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",

File diff suppressed because it is too large Load Diff

View File

@ -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 }
@ -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/"

View File

@ -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()) {

View File

@ -3,17 +3,33 @@ 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) {
@ -21,16 +37,23 @@ export async function setupBrewPack(
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 }
}