utils/github/actions: support notices and new annotation parameters
GitHub Actions annotations also suport a "notice" annotation type. You can also set the title of an annotion, and the set `endLine` and `endColumn` parameters. See https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions
This commit is contained in:
parent
ee02773c09
commit
6795a88520
@ -22,6 +22,8 @@ module GitHub
|
|||||||
class Annotation
|
class Annotation
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
|
ANNOTATION_TYPES = [:notice, :warning, :error].freeze
|
||||||
|
|
||||||
sig { params(path: T.any(String, Pathname)).returns(T.nilable(Pathname)) }
|
sig { params(path: T.any(String, Pathname)).returns(T.nilable(Pathname)) }
|
||||||
def self.path_relative_to_workspace(path)
|
def self.path_relative_to_workspace(path)
|
||||||
workspace = Pathname(ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)).realpath
|
workspace = Pathname(ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)).realpath
|
||||||
@ -33,18 +35,27 @@ module GitHub
|
|||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
type: Symbol, message: String,
|
type: Symbol,
|
||||||
file: T.nilable(T.any(String, Pathname)), line: T.nilable(Integer), column: T.nilable(Integer)
|
message: String,
|
||||||
|
title: T.nilable(String),
|
||||||
|
file: T.nilable(T.any(String, Pathname)),
|
||||||
|
line: T.nilable(Integer),
|
||||||
|
end_line: T.nilable(Integer),
|
||||||
|
column: T.nilable(Integer),
|
||||||
|
end_column: T.nilable(Integer),
|
||||||
).void
|
).void
|
||||||
}
|
}
|
||||||
def initialize(type, message, file: nil, line: nil, column: nil)
|
def initialize(type, message, title: nil, file: nil, line: nil, end_line: nil, column: nil, end_column: nil)
|
||||||
raise ArgumentError, "Unsupported type: #{type.inspect}" unless [:warning, :error].include?(type)
|
raise ArgumentError, "Unsupported type: #{type.inspect}" if ANNOTATION_TYPES.exclude?(type)
|
||||||
|
|
||||||
@type = type
|
@type = type
|
||||||
@message = Tty.strip_ansi(message)
|
@message = Tty.strip_ansi(message)
|
||||||
|
@title = Tty.strip_ansi(title) if title
|
||||||
@file = self.class.path_relative_to_workspace(file) if file
|
@file = self.class.path_relative_to_workspace(file) if file
|
||||||
@line = Integer(line) if line
|
@line = Integer(line) if line
|
||||||
|
@end_line = Integer(end_line) if end_line
|
||||||
@column = Integer(column) if column
|
@column = Integer(column) if column
|
||||||
|
@end_column = Integer(end_column) if end_column
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -56,10 +67,24 @@ module GitHub
|
|||||||
|
|
||||||
if @line
|
if @line
|
||||||
metadata << ",line=#{@line}"
|
metadata << ",line=#{@line}"
|
||||||
metadata << ",col=#{@column}" if @column
|
metadata << ",endLine=#{@end_line}" if @end_line
|
||||||
|
|
||||||
|
if @column
|
||||||
|
metadata << ",col=#{@column}"
|
||||||
|
metadata << ",endColumn=#{@end_column}" if @end_column
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @title
|
||||||
|
metadata << if @file
|
||||||
|
","
|
||||||
|
else
|
||||||
|
" "
|
||||||
|
end
|
||||||
|
metadata << "title=#{Actions.escape(@title)}"
|
||||||
|
end
|
||||||
|
|
||||||
"::#{metadata}::#{Actions.escape(@message)}"
|
"::#{metadata}::#{Actions.escape(@message)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user