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 package-lock=false
lockfile=true lockfile=true
public-hoist-pattern=['*eslint*', '*prettier*', '*@types*']

View File

@ -29,6 +29,7 @@ words:
- iarna - iarna
- cobertura - cobertura
- copr - copr
- pnpx
- CPATH - CPATH
- Cppcheck - Cppcheck
- CPPFLAGS - 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", "numerous": "1.0.3",
"envosman": "workspace:*", "envosman": "workspace:*",
"p-timeout": "^6.1.2", "p-timeout": "^6.1.2",
"parcel": "2.12.0", "parcel": "2.0.0-canary.1717",
"path-exists": "^5.0.0", "path-exists": "^5.0.0",
"patha": "^0.4.1", "patha": "^0.4.1",
"prettier": "3.2.2", "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 // 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/"

View File

@ -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, overwrite: false })
} }
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {

View File

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