Class: Homebrew::DevCmd::CaskCi Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/cask-ci.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/cask_ci.rbi

Overview

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.

Implements the private helpers used by Homebrew Cask's CI workflow.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

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

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::DevCmd::CaskCi::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/cask_ci.rbi', line 10

def args; end

#run ⇒ 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.



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
93
94
95
96
97
98
99
100
# File 'dev-cmd/cask-ci.rb', line 36

def run
  operation = args.named.fetch(0)
  cask_path = args.named.second

  case operation
  when "info"
    cask = load_cask(require_cask_path!(operation, cask_path))

    manual_installer = cask.artifacts.any? do |artifact|
      artifact.is_a?(Cask::Artifact::Installer) && artifact.manual_install
    end

    macos_requirement_satisfied = cask.depends_on.macos&.satisfied? != false
    cask_conflicts = cask.conflicts_with&.dig(:cask).to_a.select do |conflict|
      Cask::CaskLoader.load(conflict).installed?
    end
    formula_conflicts = cask.conflicts_with&.dig(:formula).to_a.select do |conflict|
      Formula[conflict].any_version_installed?
    end

    dependencies = Cask::Installer.new(cask).missing_cask_and_formula_dependencies
    cask_dependencies = dependencies.grep(Cask::Cask).map(&:full_name)
    formula_dependencies = dependencies.grep(Formula).map(&:full_name)

    File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |file|
      file.puts "manual_installer=#{JSON.generate(manual_installer)}"
      file.puts "macos_requirement_satisfied=#{JSON.generate(macos_requirement_satisfied)}"
      file.puts "formula_dependencies=#{JSON.generate(formula_dependencies)}"
    end

    File.open(ENV.fetch("GITHUB_ENV"), "a") do |file|
      file.puts "CASK_CONFLICTS=#{cask_conflicts.join(" ")}" if cask_conflicts.present?
      file.puts "CASK_DEPENDENCIES=#{cask_dependencies.join(" ")}" if cask_dependencies.present?
      file.puts "FORMULA_CONFLICTS=#{formula_conflicts.join(" ")}" if formula_conflicts.present?
    end
  when "install"
    cask = load_cask(require_cask_path!(operation, cask_path))
    raise Cask::CaskError, "#{cask} is already installed." if cask.installed?

    Cask::Installer.new(cask, verbose: args.verbose?).install
    Homebrew.messages.display_messages(force_caveats: true)
  when "snapshot"
    raise UsageError, "The `snapshot` operation does not accept a cask." if cask_path

    File.open(ENV.fetch("GITHUB_ENV"), "a") do |file|
      # The HOMEBREW_ prefix allows the snapshot to survive brew's environment filtering.
      file.puts "HOMEBREW_SNAPSHOT_BEFORE=#{JSON.generate(system_snapshot)}"
    end
  when "zap-check"
    Cask::CI::ZapCheck.run(require_cask_path!(operation, cask_path))
  when "check"
    checked_cask_path = require_cask_path!(operation, cask_path)
    before = JSON.parse(ENV.fetch("HOMEBREW_SNAPSHOT_BEFORE", "{}"), symbolize_names: true)
    after = system_snapshot
    errors = Cask::CI::Check.errors(before, after, cask: load_cask(checked_cask_path))

    errors.each do |error|
      puts GitHub::Actions::Annotation.new(:error, error, file: checked_cask_path)
    end

    Homebrew.failed = true if errors.any?
  else
    raise UsageError, "Unknown cask CI operation: #{operation}"
  end
end