Merge pull request #8671 from reitermarkus/audit-annotations
Output annotations for `brew cask audit` (again).
This commit is contained in:
commit
d8905d5a33
@ -1,5 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "utils/github/actions"
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
class Cmd
|
class Cmd
|
||||||
# Implementation of the `brew cask audit` command.
|
# Implementation of the `brew cask audit` command.
|
||||||
@ -57,7 +59,19 @@ module Cask
|
|||||||
odebug "Auditing Cask #{cask}"
|
odebug "Auditing Cask #{cask}"
|
||||||
result = Auditor.audit(cask, **options)
|
result = Auditor.audit(cask, **options)
|
||||||
|
|
||||||
result[:warnings].empty? && result[:errors].empty?
|
next true if result[:warnings].empty? && result[:errors].empty?
|
||||||
|
|
||||||
|
if ENV["GITHUB_ACTIONS"]
|
||||||
|
cask_path = cask.sourcefile_path
|
||||||
|
annotations = (result[:warnings].map { |w| [:warning, w] } + result[:errors].map { |e| [:error, e] })
|
||||||
|
.map { |type, message| GitHub::Actions::Annotation.new(type, message, file: cask_path) }
|
||||||
|
|
||||||
|
annotations.each do |annotation|
|
||||||
|
puts annotation if annotation.relevant?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
return if failed_casks.empty?
|
return if failed_casks.empty?
|
||||||
|
|||||||
@ -15,8 +15,15 @@ module Homebrew
|
|||||||
success = check_style_impl(files, :print, **options)
|
success = check_style_impl(files, :print, **options)
|
||||||
|
|
||||||
if ENV["GITHUB_ACTIONS"] && !success
|
if ENV["GITHUB_ACTIONS"] && !success
|
||||||
offenses = check_style_json(files, **options)
|
check_style_json(files, **options).each do |path, offenses|
|
||||||
puts offenses.to_github_annotations
|
offenses.each do |o|
|
||||||
|
line = o.location.line
|
||||||
|
column = o.location.line
|
||||||
|
|
||||||
|
annotation = GitHub::Actions::Annotation.new(:error, o.message, file: path, line: line, column: column)
|
||||||
|
puts annotation if annotation.relevant?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
success
|
success
|
||||||
@ -236,26 +243,6 @@ module Homebrew
|
|||||||
def each(*args, &block)
|
def each(*args, &block)
|
||||||
@offenses.each(*args, &block)
|
@offenses.each(*args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_github_annotations
|
|
||||||
workspace = ENV["GITHUB_WORKSPACE"]
|
|
||||||
return [] if workspace.blank?
|
|
||||||
|
|
||||||
workspace = Pathname(workspace).realpath
|
|
||||||
|
|
||||||
@offenses.flat_map do |path, offenses|
|
|
||||||
relative_path = path.relative_path_from(workspace)
|
|
||||||
|
|
||||||
# Only generate annotations for paths relative to the `GITHUB_WORKSPACE` directory.
|
|
||||||
next [] if relative_path.descend.next.to_s == ".."
|
|
||||||
|
|
||||||
offenses.map do |o|
|
|
||||||
line = o.location.line
|
|
||||||
column = o.location.line
|
|
||||||
GitHub::Actions::Annotation.new(:error, o.message, file: relative_path, line: line, column: column)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# A style offense.
|
# A style offense.
|
||||||
|
|||||||
@ -14,12 +14,20 @@ module GitHub
|
|||||||
|
|
||||||
# Helper class for formatting annotations on GitHub Actions.
|
# Helper class for formatting annotations on GitHub Actions.
|
||||||
class Annotation
|
class Annotation
|
||||||
|
def self.path_relative_to_workspace(path)
|
||||||
|
workspace = Pathname(ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)).realpath
|
||||||
|
path = Pathname(path)
|
||||||
|
return path unless path.exist?
|
||||||
|
|
||||||
|
path.realpath.relative_path_from(workspace)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(type, message, file: nil, line: nil, column: nil)
|
def initialize(type, message, file: nil, line: nil, column: nil)
|
||||||
raise ArgumentError, "Unsupported type: #{type.inspect}" unless [:warning, :error].include?(type)
|
raise ArgumentError, "Unsupported type: #{type.inspect}" unless [:warning, :error].include?(type)
|
||||||
|
|
||||||
@type = type
|
@type = type
|
||||||
@message = String(message)
|
@message = String(message)
|
||||||
@file = Pathname(file) if file
|
@file = self.class.path_relative_to_workspace(file) if file
|
||||||
@line = Integer(line) if line
|
@line = Integer(line) if line
|
||||||
@column = Integer(column) if column
|
@column = Integer(column) if column
|
||||||
end
|
end
|
||||||
@ -33,6 +41,14 @@ module GitHub
|
|||||||
|
|
||||||
"::#{@type}#{metadata}::#{Actions.escape(@message)}"
|
"::#{@type}#{metadata}::#{Actions.escape(@message)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# An annotation is only relevant if the corresponding `file` is relative to
|
||||||
|
# the `GITHUB_WORKSPACE` directory or if no `file` is specified.
|
||||||
|
def relevant?
|
||||||
|
return true if @file.nil?
|
||||||
|
|
||||||
|
@file.descend.next.to_s != ".."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user