diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c9af0ded6..1de3c9d20e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,27 +199,22 @@ jobs: - name: Compare installed and running apps and services with snapshot run: | brew ruby -r "$(brew --repository homebrew/cask)/cmd/lib/check.rb" <<'EOF' + require "cask/cask_loader" + require "utils/github/actions" + before = JSON.parse(<<~'EOS').transform_keys(&:to_sym) ${{ steps.snapshot.outputs.before }} EOS after = Check.all - errors = Check.errors(before, after) + cask = Cask::CaskLoader.load('${{ matrix.cask.path }}') + errors = Check.errors(before, after, cask: cask) errors.each do |error| onoe error + puts GitHub::Actions::Annotation.new(:error, error, file: '${{ matrix.cask.path }}') end - error = errors.map { |e| - Tty.strip_ansi(e) - .gsub(/\r/, '%0D') - .gsub(/\n/, '%0A') - .gsub(/]/, '%5D') - .gsub(/;/, '%3B') - }.join("\n\n") - - puts "::error file=${{ matrix.cask.path }}::#{error}" - exit 1 if errors.any? EOF if: always() && steps.snapshot.outcome == 'success' diff --git a/cmd/brewcask-ci.rb b/cmd/brewcask-ci.rb index 2b4a090acc..752f0e0d21 100644 --- a/cmd/brewcask-ci.rb +++ b/cmd/brewcask-ci.rb @@ -92,7 +92,7 @@ module Cask after = Check.all - errors = Check.errors(before, after) + errors = Check.errors(before, after, cask: cask) next success if errors.empty? diff --git a/cmd/lib/check.rb b/cmd/lib/check.rb index b2eff52a48..16a574ecff 100644 --- a/cmd/lib/check.rb +++ b/cmd/lib/check.rb @@ -76,7 +76,9 @@ module Check CHECKS.transform_values(&:call) end - def self.errors(before, after) + def self.errors(before, after, cask:) + uninstall_directives = cask.artifacts.select { |a| a.class == Cask::Artifact::Uninstall }.first&.directives || {} + diff = {} CHECKS.each_key do |name| @@ -125,13 +127,13 @@ module Check .added .reject { |id| id.match?(/\.\d+\Z/) } - if running_apps.any? + if (running_apps - uninstall_directives.fetch(:quit, [])).any? message = "Some applications are still running, add them to #{Formatter.identifier("uninstall quit:")}\n" message += running_apps.join("\n") errors << message end - if loaded_launchjobs.any? + if (loaded_launchjobs - uninstall_directives.fetch(:launchctl, [])).any? message = "Some launch jobs were not unloaded, add them to #{Formatter.identifier("uninstall launchctl:")}\n" message += loaded_launchjobs.join("\n") errors << message