From af10d13381bb89045a1359a5b8c6274189f5f542 Mon Sep 17 00:00:00 2001 From: Alec Clarke Date: Sun, 8 Sep 2019 09:09:37 -0400 Subject: [PATCH] Check blacklisted Casks when auditing. In some cases, certain Casks shouldn't be resubmitted for specific reasons: difficult to maintain, developers maintain their own version, ... To make sure these cases are restricted - we can add them to a blacklist and have the blacklist checked as part of the `brew cask audit` steps. --- Library/Homebrew/cask/audit.rb | 9 +++++++ Library/Homebrew/cask/blacklist.rb | 16 ++++++++++++ Library/Homebrew/test/cask/audit_spec.rb | 26 +++++++++++++++++-- Library/Homebrew/test/cask/blacklist_spec.rb | 21 +++++++++++++++ .../support/fixtures/cask/Casks/adobe-air.rb | 10 +++++++ .../fixtures/cask/Casks/adobe-illustrator.rb | 10 +++++++ .../fixtures/third-party/Casks/pharo.rb | 10 +++++++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 Library/Homebrew/cask/blacklist.rb create mode 100644 Library/Homebrew/test/cask/blacklist_spec.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/adobe-air.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/adobe-illustrator.rb create mode 100644 Library/Homebrew/test/support/fixtures/third-party/Casks/pharo.rb diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index c39290c5a9..6bb7739e3a 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "cask/blacklist" require "cask/checkable" require "cask/download" require "digest" @@ -30,6 +31,7 @@ module Cask end def run! + check_blacklist check_required_stanzas check_version check_sha256 @@ -320,6 +322,13 @@ module Cask add_error "appcast at URL '#{appcast_stanza}' offline or looping" end + def check_blacklist + return if cask.tap&.user != "Homebrew" + return unless reason = Blacklist.blacklisted_reason(cask.token) + + add_error "#{cask.token} is blacklisted: #{reason}" + end + def check_https_availability return unless download diff --git a/Library/Homebrew/cask/blacklist.rb b/Library/Homebrew/cask/blacklist.rb new file mode 100644 index 0000000000..c37ac82fef --- /dev/null +++ b/Library/Homebrew/cask/blacklist.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Cask + module Blacklist + def self.blacklisted_reason(name) + case name + when /^adobe\-(after|illustrator|indesign|photoshop|premiere)/ + "Adobe casks were removed because they are too difficult to maintain." + when /^audacity$/ + "Audacity was removed because it is too difficult to download programmatically." + when /^pharo$/ + "Pharo developers maintain their own tap." + end + end + end +end diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index e25bd35bac..48e984e476 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -399,6 +399,28 @@ describe Cask::Audit, :cask do end end + describe "blacklist checks" do + context "when the Cask isn't blacklisted" do + let(:cask_token) { "adobe-air" } + + it { is_expected.to pass } + end + + context "when the Cask is blacklisted" do + context "and it's in the official Homebrew tap" do + let(:cask_token) { "adobe-illustrator" } + + it { is_expected.to fail_with(/#{cask_token} is blacklisted: \w+/) } + end + + context "and it isn't in the official Homebrew tap" do + let(:cask_token) { "pharo" } + + it { is_expected.to pass } + end + end + end + describe "latest with auto_updates checks" do let(:warning_msg) { "Casks with `version :latest` should not use `auto_updates`" } @@ -541,8 +563,8 @@ describe Cask::Audit, :cask do context "when an exception is raised" do let(:cask) { instance_double(Cask::Cask) } - it "does not fail" do - expect(cask).to receive(:version).and_raise(StandardError.new) + it "fails the audit" do + expect(cask).to receive(:tap).and_raise(StandardError.new) expect(subject).to fail_with(/exception while auditing/) end end diff --git a/Library/Homebrew/test/cask/blacklist_spec.rb b/Library/Homebrew/test/cask/blacklist_spec.rb new file mode 100644 index 0000000000..3213b5a805 --- /dev/null +++ b/Library/Homebrew/test/cask/blacklist_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +describe Cask::Blacklist, :cask do + describe "::blacklisted_reason" do + matcher :blacklist do |name| + match do |expected| + expected.blacklisted_reason(name) + end + end + + it { is_expected.not_to blacklist("adobe-air") } + it { is_expected.to blacklist("adobe-after-effects") } + it { is_expected.to blacklist("adobe-illustrator") } + it { is_expected.to blacklist("adobe-indesign") } + it { is_expected.to blacklist("adobe-photoshop") } + it { is_expected.to blacklist("adobe-premiere") } + it { is_expected.to blacklist("audacity") } + it { is_expected.to blacklist("pharo") } + it { is_expected.not_to blacklist("non-blacklisted-cask") } + end +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-air.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-air.rb new file mode 100644 index 0000000000..39c7214180 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-air.rb @@ -0,0 +1,10 @@ +cask 'adobe-air' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'https://brew.sh/TestCask.dmg' + name 'Adobe Air' + homepage 'https://brew.sh/' + + app 'TestCask.app' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-illustrator.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-illustrator.rb new file mode 100644 index 0000000000..afe643362a --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/adobe-illustrator.rb @@ -0,0 +1,10 @@ +cask 'adobe-illustrator' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'https://brew.sh/TestCask.dmg' + name 'Adobe Illustrator' + homepage 'https://brew.sh/' + + app 'TestCask.app' +end diff --git a/Library/Homebrew/test/support/fixtures/third-party/Casks/pharo.rb b/Library/Homebrew/test/support/fixtures/third-party/Casks/pharo.rb new file mode 100644 index 0000000000..8918c6565f --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/third-party/Casks/pharo.rb @@ -0,0 +1,10 @@ +cask 'pharo' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'https://brew.sh/ThirdParty.dmg' + name 'Pharo' + homepage 'https://brew.sh/' + + app 'ThirdParty.app' +end