Skip to content

Commit 9f7daa1

Browse files
committed
Avoid install warning annotations
- Keep idempotent `brew install` warnings visible in CI logs. - Avoid noisy GitHub Actions annotations for harmless installs. - Preserve annotation behaviour for other `opoo` callers.
1 parent fe6709d commit 9f7daa1

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

Library/Homebrew/install.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def install_formula?(
147147
elsif only_dependencies
148148
return true
149149
elsif !quiet
150-
opoo <<~EOS
150+
opoo_without_github_actions_annotation <<~EOS
151151
#{formula.full_name} #{formula.pkg_version} is already installed and up-to-date.
152152
To reinstall #{formula.pkg_version}, run:
153153
brew reinstall #{formula.name}
@@ -185,15 +185,14 @@ def install_formula?(
185185
brew link #{formula.full_name}
186186
EOS
187187
else
188-
msg = if quiet
189-
nil
190-
else
191-
<<~EOS
188+
unless quiet
189+
opoo_without_github_actions_annotation <<~EOS
192190
#{msg} and up-to-date.
193191
To reinstall #{formula.pkg_version}, run:
194192
brew reinstall #{formula.name}
195193
EOS
196194
end
195+
msg = nil
197196
end
198197
opoo msg if msg
199198
elsif !formula.any_version_installed? && (old_formula = formula.old_installed_formulae.first)

Library/Homebrew/test/utils/output_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "utils/output"
5+
require "utils/github/actions"
56

67
RSpec.describe Utils::Output do
78
let(:klass) { Utils::Output }
@@ -136,6 +137,18 @@ def esc(code)
136137
end
137138
end
138139

140+
describe "#opoo_without_github_actions_annotation" do
141+
it "prints a warning without a GitHub Actions annotation" do
142+
with_env(GITHUB_ACTIONS: "true") do
143+
expect(GitHub::Actions).not_to receive(:puts_annotation_if_env_set!)
144+
145+
expect do
146+
klass.opoo_without_github_actions_annotation "foo"
147+
end.to output("Warning: foo\n").to_stderr
148+
end
149+
end
150+
end
151+
139152
describe "#odie" do
140153
it "exits with 1" do
141154
expect do

Library/Homebrew/utils/output.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def opoo(message)
7676
end
7777
end
7878

79+
sig { params(message: T.any(String, Exception)).void }
80+
def opoo_without_github_actions_annotation(message)
81+
require "utils/github/actions"
82+
return opoo(message) unless GitHub::Actions.env_set?
83+
84+
require "utils/formatter"
85+
86+
Tty.with($stderr) do |stderr|
87+
stderr.puts Formatter.warning(message, label: "Warning")
88+
end
89+
end
90+
7991
# Print a warning message only if not running in GitHub Actions.
8092
#
8193
# @api public

0 commit comments

Comments
 (0)