Skip to content

Commit 8d0a967

Browse files
committed
fix: avoid already installed warnings for brew
1 parent 6cb9980 commit 8d0a967

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/setup-brew/src/install-pack.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from "path"
22
import { info, warning } from "ci-log"
3-
import { execaSync } from "execa"
3+
import { execaSync } from "execa" // brew is not thread-safe
44
import which from "which"
55
import type { InstallationInfo } from "./InstallationInfo.js"
66
import type { BrewPackOptions } from "./install-pack-options.js"
@@ -53,11 +53,21 @@ export async function installBrewPack(
5353
}
5454
}
5555

56-
// brew is not thread-safe
57-
execaSync(brewPath, args, { stdio: "inherit" })
56+
// dry run to check if the package is already installed
57+
const dryRun = execaSync(brewPath, [...args, "--dry-run"], { stdio: "pipe" })
58+
const isAlreadyInstalled = dryRun.exitCode === 0
59+
&& (new RegExp(`Warning: ${name}.* is already installed and up-to-date.[\\s\\S]*`)).test(dryRun.stderr)
5860

59-
const installDir = await brewPackInstallDir(name, version)
61+
if (isAlreadyInstalled) {
62+
// if the package is already installed and up-to-date, skip the installation
63+
info(`${name} ${version ?? ""} is already installed and up-to-date`)
64+
} else {
65+
// install the package if not already installed
66+
execaSync(brewPath, args, { stdio: "inherit" })
67+
}
6068

69+
// get the installation directory
70+
const installDir = await brewPackInstallDir(name, version)
6171
if (installDir === undefined) {
6272
warning(`Failed to find installation directory for ${name} ${version}`)
6373
return { binDir: getBrewBinDir(), installDir: undefined }

0 commit comments

Comments
 (0)