homebrew-cask/cmd/brewcask-ci.rb

141 lines
3.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: false
require "utils/github"
require "utils/formatter"
require_relative "lib/check"
require_relative "lib/ci_matrix"
module Cask
class Cmd
class Ci < AbstractCommand
def self.description
"Test changes in a Homebrew Cask tap."
end
def run
with_env HOMEBREW_DEVELOPER: nil do
odeprecated "brew cask ci"
end
raise CaskError, "This command isnt meant to be run locally." unless ENV.key?("CI")
tap = Tap.from_path(Dir.pwd)
matrix = CiMatrix.generate(tap)
$stdout.sync = true
$stderr.sync = true
overall_success = true
matrix.each do |m|
path = m[:cask]
cask = CaskLoader.load(path)
overall_success &= step "brew cask style #{cask.token}" do
Style.run(cask.sourcefile_path)
true
end
overall_success &= step "brew cask audit #{cask.token}" do
Audit.run(*m[:audit_args], cask.sourcefile_path)
true
end
if (macos_requirement = cask.depends_on.macos) && !macos_requirement.satisfied?
opoo "Skipping installation: #{macos_requirement.message}"
next
end
was_installed = cask.installed?
installer = Installer.new(cask, verbose: true)
before = nil
cask_and_formula_dependencies = nil
overall_success &= step "brew cask install #{cask.token}" do
cask_and_formula_dependencies = installer.missing_cask_and_formula_dependencies
if was_installed
old_cask = CaskLoader.load(cask.installed_caskfile)
Installer.new(old_cask, verbose: true).zap
end
before = Check.all
installer.install
end
overall_success &= step "brew cask uninstall #{cask.token}" do
success = begin
if manual_installer?(cask)
puts "Cask has a manual installer, skipping..."
else
installer.uninstall
end
true
rescue => e
$stderr.puts e.message
$stderr.puts e.backtrace
false
ensure
cask_and_formula_dependencies.reverse_each do |cask_or_formula|
next unless cask_or_formula.is_a?(Cask)
Installer.new(cask_or_formula, verbose: true).uninstall if cask_or_formula.installed?
end
end
after = Check.all
errors = Check.errors(before, after)
next success if errors.empty?
errors.each do |error|
onoe error
end
false
end
end
if overall_success
puts Formatter.success("Build finished successfully.", label: "Success")
return
end
raise CaskError, "Build failed."
end
private
def step(name)
group = Formatter.headline(name.to_s, color: :yellow)
puts "::group::#{group}"
success = begin
yield != false
rescue => e
$stderr.puts e.message
$stderr.puts e.backtrace
false
end
puts "::endgroup::#{group}"
success
end
def manual_installer?(cask)
cask.artifacts.any? { |artifact| artifact.is_a?(Artifact::Installer::ManualInstaller) }
end
end
end
end