Class: Homebrew::TestBot::Casks Private

Inherits:
Test show all
Defined in:
test_bot/casks.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Instance Attribute Summary

Attributes inherited from Test

#steps

Instance Method Summary collapse

Methods inherited from Test

#failed_steps, #ignored_steps, #test

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Instance Method Details

#run!(names, added_casks:, args:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'test_bot/casks.rb', line 13

def run!(names, added_casks:, args:)
  return if names.empty?

  test_header(:Casks)
  default_tap = tap || CoreCaskTap.instance
  added_casks = added_casks.map { |name| name.include?("/") ? name : "#{default_tap}/#{name}" }
  Utils::Shell.with_env(HOMEBREW_TEST_BOT_CASKS: ("1" if CoreCaskTap.instance.installed?)) do
    CoreCaskTap.instance.clear_cache
    names.each do |name|
      name = "#{default_tap}/#{name}" if name.exclude?("/") && !default_tap.core_cask_tap?
      begin
        cask = Cask::CaskLoader.load(name)
      rescue => e
        # Even a dry run needs the cask definition to plan its steps.
        test("Load cask", name, dry_run: false) { raise e }
        next
      end

      if cask.disabled? || !cask.meets_platform_requirements?(Utils::Bottles.tag)
        info_header "Skipping #{name} (disabled or unsupported on #{Utils::Bottles.tag})"
        next
      end

      fetched = fetch(:cask, name, args:)
      new_cask = added_casks.include?("#{cask.tap}/#{cask.token}") || added_casks.include?(name)
      test(*audit_command(:cask, name, args:, new_package: new_cask), report_analytics: true)
      next if args.skip_install? || !fetched.passed?

      path = cask.sourcefile_path || raise("No tap file for #{cask.full_name}")
      installer = Cask::Installer.new(cask, verbose: args.verbose?)
      if cleanup?(args)
        conflicts = T.let(nil, T.nilable(T::Array[String]))
        test("Resolve conflicts", cask.full_name, dry_run: false) { conflicts = installer.installed_conflicts }
        next unless conflicts

        test "brew", "uninstall", "--cask", *conflicts if conflicts.present?
        test "brew", "uninstall", "--cask", "--force", "--zap", cask.full_name
      end

      dependencies = T.let([], T::Array[Cask::Cask])
      resolved = test("Resolve dependencies", cask.full_name) do
        dependencies = installer.missing_cask_and_formula_dependencies.grep(Cask::Cask)
      end
      next unless resolved.passed?

      snapshot = (@dry_run ? {} : Cask::CI::Check.all) if cleanup?(args) && Utils::Bottles.tag.macos?
      already_installed = cask.installed?
      install_args = ["brew", "install", "--cask", cask.full_name]
      install_args << "--verbose" if args.verbose?
      begin
        if already_installed && !@dry_run
          test(*install_args) { raise Cask::CaskError, "#{cask} is already installed." }
          next
        end
        installed = test(*install_args,
                         env:              { "HOMEBREW_NO_ASK" => "1", "HOMEBREW_NO_INSTALL_CLEANUP" => "1" },
                         report_analytics: true).passed?
        if installed && snapshot
          test("Check zap stanza", cask.full_name, ignore_failures: true) { Cask::CI::ZapCheck.run(path.to_s) }
        end
      ensure
        if !already_installed && (installed || cask.installed?) &&
           cask.artifacts.grep(Cask::Artifact::Installer).none?(&:manual_install)
          test "brew", "uninstall", "--cask", cask.full_name
        end
        installed_dependencies = dependencies.select(&:installed?).map(&:full_name).reverse
        test "brew", "uninstall", "--cask", *installed_dependencies if installed_dependencies.present?
        if installed && snapshot
          test("Check uninstall", cask.full_name) do
            errors = Cask::CI::Check.errors(snapshot, Cask::CI::Check.all, cask:)
            errors.each { |error| puts GitHub::Actions::Annotation.new(:error, error, file: path.to_s) }
            raise Cask::CaskError, errors.join("\n") if errors.any?
          end
        end
      end
    end
  ensure
    CoreCaskTap.instance.clear_cache
  end
end