From 4020f50c14d6b3c845f6d1c41c986904aa6c1aae Mon Sep 17 00:00:00 2001 From: commitay Date: Mon, 26 Mar 2018 21:25:00 +1000 Subject: [PATCH] cask audit: check for appcast if the cask uses github releases --- Library/Homebrew/cask/lib/hbc/audit.rb | 8 ++++++++ Library/Homebrew/test/cask/audit_spec.rb | 19 +++++++++++++++++++ .../cask/Casks/github-with-appcast.rb | 14 ++++++++++++++ .../cask/Casks/github-without-appcast.rb | 12 ++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/github-with-appcast.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/github-without-appcast.rb diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index a3224380ab..54c6296438 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -34,6 +34,7 @@ module Hbc check_single_pre_postflight check_single_uninstall_zap check_untrusted_pkg + check_github_releases_appcast self rescue StandardError => e odebug "#{e.message}\n#{e.backtrace.join("\n")}" @@ -227,6 +228,13 @@ module Hbc end end + def check_github_releases_appcast + return if cask.appcast + return unless cask.url.to_s =~ %r{github.com/([^/]+)/([^/]+)/releases/download/(\S+)} + + add_warning "Cask uses GitHub releases, please add an appcast. See https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/appcast.md" + end + def check_url return unless cask.url check_download_url_format diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 93da10d0eb..091e8bbb85 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -368,6 +368,25 @@ describe Hbc::Audit, :cask do end end + describe "GitHub releases appcast check" do + let(:error_msg) { /Cask uses GitHub releases/ } + + context "when the Cask does not use GitHub releases" do + let(:cask_token) { "basic-cask" } + it { should_not warn_with(error_msg) } + end + + context "when the Cask uses GitHub releases and has an appcast" do + let(:cask_token) { "github-with-appcast" } + it { should_not warn_with(error_msg) } + end + + context "when the Cask uses GitHub releases and does not have an appcast" do + let(:cask_token) { "github-without-appcast" } + it { is_expected.to warn_with(error_msg) } + end + end + describe "preferred download URL formats" do let(:warning_msg) { /URL format incorrect/ } diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/github-with-appcast.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/github-with-appcast.rb new file mode 100644 index 0000000000..3024ced934 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/github-with-appcast.rb @@ -0,0 +1,14 @@ +cask 'github-with-appcast' do + version '1.0' + sha256 'a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9' + + url "https://github.com/user/project/releases/download/#{version}/github.pkg" + appcast 'https://github.com/user/project/releases.atom', + checkpoint: '56d1707d3065bf0c75d75d7738571285273b7bf366d8f0f5a53eb8b457ad2453' + name 'github' + homepage 'https://github.com/user/project' + + pkg 'github.pkg' + + uninstall pkgutil: 'com.github' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/github-without-appcast.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/github-without-appcast.rb new file mode 100644 index 0000000000..9e7e17864d --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/github-without-appcast.rb @@ -0,0 +1,12 @@ +cask 'github-without-appcast' do + version '1.0' + sha256 'a69e7357bea014f4c14ac9699274f559086844ffa46563c4619bf1addfd72ad9' + + url "https://github.com/user/project/releases/download/#{version}/github.pkg" + name 'github' + homepage 'https://github.com/user/project' + + pkg 'github.pkg' + + uninstall pkgutil: 'com.github' +end