Class: Homebrew::DevCmd::GenerateCaskCiMatrix Private

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

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.

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::GenerateCaskCiMatrix::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/generate_cask_ci_matrix.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.

Raises:



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
101
102
103
104
105
106
107
108
109
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 43

def run
  # odeprecated "`brew generate-cask-ci-matrix`", "`brew determine-test-runners --cask`"
  pr_url = args.named if args.url?

  repository = ENV.fetch("GITHUB_REPOSITORY", nil)
  raise UsageError, "The `$GITHUB_REPOSITORY` environment variable must be set." if repository.blank?

  tap = Tap.fetch(repository)

  if !args.syntax_only? && !args.testing_casks && !args.casks? && !args.url?
    raise UsageError, "Specify `--testing-casks`, `--cask` or `--url`."
  end
  if (args.casks? || args.url?) && args.named.empty?
    raise UsageError, "Please provide a `--cask` or `--url` argument."
  end
  raise UsageError, "Only one `--url` can be specified." if pr_url&.count&.> 1

  labels = Cask::CI::RunnerMatrix.labels(pr_url&.first)
  cask_jobs = if args.syntax_only? || labels.include?("ci-syntax-only")
    []
  else
    Homebrew::API.with_no_api_env do
      if (testing_casks = args.testing_casks)
        cask_names = testing_casks.split(/[,\s]+/).reject(&:empty?)
        added_casks = args.added_casks.to_a
      else
        require "test_bot/packages_detect"

        added_casks, modified_casks, =
          TestBot::PackagesDetect.changed_packages(tap, "origin...HEAD", check_cask_paths: true).fetch(:cask)
        cask_names = if args.casks?
          args.named
        else
          added_casks | modified_casks
        end
      end
      Cask::CI::RunnerMatrix.generate(tap, cask_names, added_casks:, labels:,
                                      skip_install: args.skip_install?, new_cask: args.new?)
    end
  end

  # Older workflows get both syntax and cask jobs from the `matrix` output.
  runner = Cask::CI::RunnerMatrix.random_runner.fetch(:name)
  syntax_job = {
    name:   "tap_syntax (#{runner})",
    tap:    tap.name,
    runner:,
    stable: false,
  }
  syntax_job[:skip_audit] = true if cask_jobs.any?
  matrix = [
    syntax_job,
    syntax_job.merge(name: "tap_syntax (stable) (#{runner})", stable: true, skip_audit: true),
    *cask_jobs,
  ]

  Cask::CI::RunnerMatrix.check_size!(matrix.size)

  puts JSON.pretty_generate(matrix)
  github_output = ENV.fetch("GITHUB_OUTPUT", nil)
  return unless github_output

  File.open(github_output, "a") do |f|
    f.puts "runners=#{JSON.generate(cask_jobs)}"
    f.puts "matrix=#{JSON.generate(matrix)}"
  end
end