From 2fa5e200b74c51e05ba96928d221a022b659730f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 11 Aug 2020 07:50:10 +0200 Subject: [PATCH] Remove CI `zap` exception handling. --- cmd/brewcask-ci.rb | 33 ++-------------------------- cmd/lib/check.rb | 54 ++++++++++++++++------------------------------ 2 files changed, 20 insertions(+), 67 deletions(-) diff --git a/cmd/brewcask-ci.rb b/cmd/brewcask-ci.rb index f022afee339..7b58ae7a510 100755 --- a/cmd/brewcask-ci.rb +++ b/cmd/brewcask-ci.rb @@ -150,9 +150,9 @@ module Cask check.after - next success if check.success?(stanza: :uninstall) + errors = check.errors - errors = check.errors(stanza: :uninstall) + next true if errors.empty? errors.each do |error| $stderr.puts error @@ -163,35 +163,6 @@ module Cask false end - - next unless check.success?(stanza: :uninstall) && !check.success?(stanza: :zap) - - overall_success &= step "brew cask zap #{cask.token}" do - success = begin - Installer.new(cask, verbose: true).zap - true - rescue => e - $stderr.puts e.message - $stderr.puts e.backtrace - false - end - - check.after - - next success if check.success?(stanza: :zap) - - errors = check.errors(stanza: :zap) - - errors.each do |error| - $stderr.puts error - end - - path = Pathname(cask.sourcefile_path).relative_path_from(tap.path).to_s - puts "::error file=#{self.class.escape(path)}::#{self.class.escape(errors.join("\n\n"))}" - - $stderr.puts - false - end end if overall_success diff --git a/cmd/lib/check.rb b/cmd/lib/check.rb index 8716c3af06a..078d5e05a21 100644 --- a/cmd/lib/check.rb +++ b/cmd/lib/check.rb @@ -54,6 +54,7 @@ class Check .grep_v(/^com\.apple\./) }, }.freeze + private_constant :CHECKS class Diff attr_reader :removed, :added @@ -69,25 +70,23 @@ class Check removed.any? || added.any? end end + private_constant :Diff + + def check_all + CHECKS.transform_values(&:call) + end + private :check_all def before @diff = nil - @before = {} - - CHECKS.each do |name, block| - @before[name] = block.call - end + @before = check_all end def after @diff = nil - @after = {} - - CHECKS.each do |name, block| - @after[name] = block.call - end + @after = check_all end def diff @@ -103,30 +102,13 @@ class Check end private :diff - def success?(stanza:) - diff.values.all? { |v| filter_exceptions(v.added, stanza: stanza).none? } - end - - def zap_exception?(id) - [ - "com.microsoft.autoupdate.helper", - "com.microsoft.package.Microsoft_AU_Bootstrapper.app", - "com.microsoft.package.Microsoft_AutoUpdate.app", - "com.microsoft.update.agent", - ].include?(id) - end - - def filter_exceptions(ids, stanza:) - ids.reject { |id| stanza == :uninstall ? zap_exception?(id) : false } - end - - def errors(stanza:) + def errors errors = [] pkg_files = diff[:installed_pkgs] .added .flat_map { |id| Cask::Pkg.new(id).pkgutil_bom_all.map(&:to_s) } - installed_apps = filter_exceptions(diff[:installed_apps].added - pkg_files, stanza: stanza) + installed_apps = diff[:installed_apps].added - pkg_files if installed_apps.any? message = Formatter.error( "Some applications are still installed, add them to #{Formatter.identifier("#{stanza} delete:")}\n", @@ -136,7 +118,7 @@ class Check errors << message end - installed_kexts = filter_exceptions(diff[:installed_kexts].added, stanza: stanza) + installed_kexts = diff[:installed_kexts].added if installed_kexts.any? message = Formatter.error( "Some kernel extensions are still installed, add them to #{Formatter.identifier("#{stanza} kext:")}\n", @@ -146,7 +128,7 @@ class Check errors << message end - installed_packages = filter_exceptions(diff[:installed_pkgs].added, stanza: stanza) + installed_packages = diff[:installed_pkgs].added if installed_packages.any? message = Formatter.error( "Some packages are still installed, add them to #{Formatter.identifier("#{stanza} pkgutil:")}\n", @@ -156,7 +138,7 @@ class Check errors << message end - installed_launchjobs = filter_exceptions(diff[:installed_launchjobs].added, stanza: stanza) + installed_launchjobs = diff[:installed_launchjobs].added if installed_launchjobs.any? message = Formatter.error( "Some launch jobs are still installed, add them to #{Formatter.identifier("#{stanza} launchctl:")}\n", @@ -166,14 +148,14 @@ class Check errors << message end - running_apps = filter_exceptions(diff[:loaded_launchjobs] + running_apps = diff[:loaded_launchjobs] .added .select { |id| id.match?(/\.\d+\Z/) } - .map { |id| id.sub(/\.\d+\Z/, "") }, stanza: stanza) + .map { |id| id.sub(/\.\d+\Z/, "") } - loaded_launchjobs = filter_exceptions(diff[:loaded_launchjobs] + loaded_launchjobs = diff[:loaded_launchjobs] .added - .reject { |id| id.match?(/\.\d+\Z/) }, stanza: stanza) + .reject { |id| id.match?(/\.\d+\Z/) } if running_apps.any? message = Formatter.error(