audit: limit non-failure cask output

This commit is contained in:
Rylan Polster 2021-03-21 13:59:43 -04:00
parent 516903530a
commit 2b8d19e0bd
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
10 changed files with 74 additions and 32 deletions

View File

@ -77,7 +77,7 @@ jobs:
run: brew style --display-cop-names homebrew/core
- name: Run brew audit --skip-style on all taps
run: brew audit --skip-style
run: brew audit --skip-style --display-failures-only
- name: Set up all Homebrew taps
run: |
@ -277,10 +277,10 @@ jobs:
- name: Run brew audit --skip-style on Cask taps
run: |
brew audit --skip-style --tap=homebrew/cask
brew audit --skip-style --tap=homebrew/cask-drivers
brew audit --skip-style --tap=homebrew/cask-fonts
brew audit --skip-style --tap=homebrew/cask-versions
brew audit --skip-style --display-failures-only --tap=homebrew/cask
brew audit --skip-style --display-failures-only --tap=homebrew/cask-drivers
brew audit --skip-style --display-failures-only --tap=homebrew/cask-fonts
brew audit --skip-style --display-failures-only --tap=homebrew/cask-versions
- name: Install brew tests dependencies
run: |

View File

@ -126,8 +126,10 @@ module Cask
end
end
sig { returns(String) }
def summary
sig { params(include_passed: T::Boolean).returns(String) }
def summary(include_passed: false)
return if success? && !include_passed
summary = ["audit for #{cask}: #{result}"]
errors.each do |error|

View File

@ -18,7 +18,9 @@ module Cask
audit_token_conflicts: nil,
quarantine: nil,
any_named_args: nil,
language: nil
language: nil,
display_passes: nil,
display_failures_only: nil
)
new(
cask,
@ -31,6 +33,8 @@ module Cask
quarantine: quarantine,
any_named_args: any_named_args,
language: language,
display_passes: display_passes,
display_failures_only: display_failures_only,
).audit
end
@ -46,7 +50,9 @@ module Cask
audit_new_cask: nil,
quarantine: nil,
any_named_args: nil,
language: nil
language: nil,
display_passes: nil,
display_failures_only: nil
)
@cask = cask
@audit_download = audit_download
@ -58,6 +64,8 @@ module Cask
@audit_token_conflicts = audit_token_conflicts
@any_named_args = any_named_args
@language = language
@display_passes = display_passes
@display_failures_only = display_failures_only
end
def audit
@ -67,13 +75,18 @@ module Cask
if !language && language_blocks
language_blocks.each_key do |l|
audit = audit_languages(l)
puts audit.summary if output_summary?(audit)
summary = audit.summary(include_passed: output_passed?)
if summary.present? && output_summary?(audit)
ohai "Auditing language: #{l.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary?
puts summary
end
warnings += audit.warnings
errors += audit.errors
end
else
audit = audit_cask_instance(cask)
puts audit.summary if output_summary?(audit)
summary = audit.summary(include_passed: output_passed?)
puts summary if summary.present? && output_summary?(audit)
warnings += audit.warnings
errors += audit.errors
end
@ -84,6 +97,7 @@ module Cask
private
def output_summary?(audit = nil)
return false if @display_failures_only.present?
return true if @any_named_args.present?
return true if @audit_strict.present?
return false if audit.blank?
@ -91,9 +105,14 @@ module Cask
audit.errors?
end
def audit_languages(languages)
ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary?
def output_passed?
return false if @display_failures_only.present?
return true if @display_passes.present?
false
end
def audit_languages(languages)
original_config = cask.config
localized_config = original_config.merge(Config.new(explicit: { languages: languages }))
cask.config = localized_config

View File

@ -27,6 +27,8 @@ module Cask
description: "Run various additional style checks to determine if a new cask is eligible " \
"for Homebrew. This should be used when creating new casks and implies " \
"`--strict` and `--online`"
switch "--display-failures-only",
description: "Only display casks that fail the audit. This is the default for formulae."
end
end
@ -44,15 +46,17 @@ module Cask
results = self.class.audit_casks(
*casks,
download: args.download?,
appcast: args.appcast?,
online: args.online?,
strict: args.strict?,
new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?,
quarantine: args.quarantine?,
any_named_args: any_named_args,
language: args.language,
download: args.download?,
appcast: args.appcast?,
online: args.online?,
strict: args.strict?,
new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?,
quarantine: args.quarantine?,
any_named_args: any_named_args,
language: args.language,
display_passes: args.verbose? || args.named.count == 1,
display_failures_only: args.display_failures_only?,
)
self.class.print_annotations(results)
@ -73,7 +77,9 @@ module Cask
token_conflicts: nil,
quarantine: nil,
any_named_args: nil,
language: nil
language: nil,
display_passes: nil,
display_failures_only: nil
)
options = {
audit_download: download,
@ -85,6 +91,8 @@ module Cask
quarantine: quarantine,
language: language,
any_named_args: any_named_args,
display_passes: display_passes,
display_failures_only: display_failures_only,
}.compact
options[:quarantine] = true if options[:quarantine].nil?

View File

@ -56,6 +56,8 @@ module Homebrew
switch "--display-filename",
description: "Prefix every line of output with the file or formula name being audited, to "\
"make output easy to grep."
switch "--display-failures-only",
description: "Only display casks that fail the audit. This is the default for formulae."
switch "--skip-style",
description: "Skip running non-RuboCop style checks. Useful if you plan on running "\
"`brew style` separately. Enabled by default unless a formula is specified by name."
@ -213,15 +215,17 @@ module Homebrew
Cask::Cmd::Audit.audit_casks(
*audit_casks,
download: nil,
appcast: args.appcast?,
online: args.online?,
strict: args.strict?,
new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?,
quarantine: nil,
any_named_args: !no_named_args,
language: nil,
download: nil,
appcast: args.appcast?,
online: args.online?,
strict: args.strict?,
new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?,
quarantine: nil,
any_named_args: !no_named_args,
language: nil,
display_passes: args.verbose? || args.named.count == 1,
display_failures_only: args.display_failures_only?,
)
end

View File

@ -324,6 +324,7 @@ _brew_audit() {
--cask
--debug
--display-cop-names
--display-failures-only
--display-filename
--except
--except-cops

View File

@ -325,6 +325,7 @@ __fish_brew_complete_arg 'audit' -l audit-debug -d 'Enable debugging and profili
__fish_brew_complete_arg 'audit' -l cask -d 'Treat all named arguments as casks'
__fish_brew_complete_arg 'audit' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'audit' -l display-cop-names -d 'Include the RuboCop cop name for each violation in the output'
__fish_brew_complete_arg 'audit' -l display-failures-only -d 'Only display casks that fail the audit. This is the default for formulae'
__fish_brew_complete_arg 'audit' -l display-filename -d 'Prefix every line of output with the file or formula name being audited, to make output easy to grep'
__fish_brew_complete_arg 'audit' -l except -d 'Specify a comma-separated method list to skip running the methods named `audit_`method'
__fish_brew_complete_arg 'audit' -l except-cops -d 'Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops'

View File

@ -406,6 +406,7 @@ _brew_audit() {
'--audit-debug[Enable debugging and profiling of audit methods]' \
'--debug[Display any debugging information]' \
'(--skip-style --only-cops --except-cops)--display-cop-names[Include the RuboCop cop name for each violation in the output]' \
'--display-failures-only[Only display casks that fail the audit. This is the default for formulae]' \
'--display-filename[Prefix every line of output with the file or formula name being audited, to make output easy to grep]' \
'(--only)--except[Specify a comma-separated method list to skip running the methods named `audit_`method]' \
'(--only-cops --strict --only-cops --only --display-cop-names)--except-cops[Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops]' \

View File

@ -780,6 +780,8 @@ non-zero status if any errors are found.
Include the RuboCop cop name for each violation in the output.
* `--display-filename`:
Prefix every line of output with the file or formula name being audited, to make output easy to grep.
* `--display-failures-only`:
Only display casks that fail the audit. This is the default for formulae.
* `--skip-style`:
Skip running non-RuboCop style checks. Useful if you plan on running `brew style` separately. Enabled by default unless a formula is specified by name.
* `-D`, `--audit-debug`:

View File

@ -1062,6 +1062,10 @@ Include the RuboCop cop name for each violation in the output\.
Prefix every line of output with the file or formula name being audited, to make output easy to grep\.
.
.TP
\fB\-\-display\-failures\-only\fR
Only display casks that fail the audit\. This is the default for formulae\.
.
.TP
\fB\-\-skip\-style\fR
Skip running non\-RuboCop style checks\. Useful if you plan on running \fBbrew style\fR separately\. Enabled by default unless a formula is specified by name\.
.