Merge pull request #18561 from Homebrew/duplicate-messages-github-actions

extend/kernel: fix duplicate messages in GitHub Actions
This commit is contained in:
Mike McQuaid 2024-10-14 08:40:00 +01:00 committed by GitHub
commit fd270c78d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -64,9 +64,10 @@ module Kernel
# @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
@ -75,12 +76,13 @@ module Kernel
# @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
@ -178,8 +180,6 @@ module Kernel
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

View File

@ -43,15 +43,17 @@ module GitHub
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.