Skip to content

Commit

Permalink
Merge pull request #18561 from Homebrew/duplicate-messages-github-act…
Browse files Browse the repository at this point in the history
…ions

extend/kernel: fix duplicate messages in GitHub Actions
  • Loading branch information
MikeMcQuaid authored Oct 14, 2024
2 parents d49c35d + 7a8f9fa commit fd270c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Library/Homebrew/extend/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def oh1(title, truncate: :auto)
# @api public
sig { params(message: T.any(String, Exception)).void }
def opoo(message)
return if GitHub::Actions.puts_annotation_if_env_set(:warning, message.to_s)

Tty.with($stderr) do |stderr|
stderr.puts Formatter.warning(message, label: "Warning")
GitHub::Actions.puts_annotation_if_env_set(:warning, message.to_s)
end
end

Expand All @@ -75,12 +76,13 @@ def opoo(message)
# @api public
sig { params(message: T.any(String, Exception)).void }
def onoe(message)
require "utils/formatter"
require "utils/github/actions"
return if GitHub::Actions.puts_annotation_if_env_set(:error, message.to_s)

require "utils/formatter"

Tty.with($stderr) do |stderr|
stderr.puts Formatter.error(message, label: "Error")
GitHub::Actions.puts_annotation_if_env_set(:error, message.to_s)
end
end

Expand Down Expand Up @@ -178,8 +180,6 @@ def odeprecated(method, replacement = nil,
exception.set_backtrace(backtrace)
raise exception
elsif !Homebrew.auditing?
require "utils/github/actions"
GitHub::Actions.puts_annotation_if_env_set(:warning, message, file:, line:)
opoo message
end
end
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/utils/github/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ def self.env_set?
type: Symbol, message: String,
file: T.nilable(T.any(String, Pathname)),
line: T.nilable(Integer)
).void
).returns(T::Boolean)
}
def self.puts_annotation_if_env_set(type, message, file: nil, line: nil)
# Don't print annotations during tests, too messy to handle these.
return if ENV.fetch("HOMEBREW_TESTS", false)
return unless env_set?
return false if ENV.fetch("HOMEBREW_TESTS", false)
return false unless env_set?

std = (type == :notice) ? $stdout : $stderr
std.puts Annotation.new(type, message)

true
end

# Helper class for formatting annotations on GitHub Actions.
Expand Down

0 comments on commit fd270c7

Please sign in to comment.