Module: Cask::CI::RunnerMatrix Private

Extended by:
Utils::Output::Mixin
Defined in:
cask/ci/runner_matrix.rb

Overview

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

Selects GitHub Actions runners and audit options for each changed cask.

Constant Summary collapse

Runner =

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

T.type_alias { T::Hash[Symbol, T.any(Symbol, String)] }
MAX_JOBS =

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

256
MACOS_RUNNERS =

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

Weight for each arch must add up to 1.0.

T.let({
  { symbol: :sequoia,     name: "macos-15", arch: :arm } => 0.0,
  { symbol: :tahoe,       name: "macos-26", arch: :arm } => 0.0,
  { symbol: :golden_gate, name: "xcode-27", arch: :arm } => 1.0,
}.freeze, T::Hash[Runner, Float])
LINUX_RUNNERS =

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

T.let({
  { symbol: :linux, name: "ubuntu-latest", arch: :intel }       => 1.0,
  { symbol: :linux, name: OS::LINUX_CI_ARM_RUNNER, arch: :arm } => 1.0,
}.freeze, T::Hash[Runner, Float])
RUNNERS =

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

T.let(MACOS_RUNNERS.merge(LINUX_RUNNERS).freeze, T::Hash[Runner, Float])

Class Method Summary collapse

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

Class Method Details

.check_size!(count) ⇒ 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:



36
37
38
# File 'cask/ci/runner_matrix.rb', line 36

def self.check_size!(count)
  odie "Maximum job matrix size exceeded: #{count}/#{MAX_JOBS}" if count > MAX_JOBS
end

.filter_runners(cask) ⇒ Hash{Runner => Float}

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.

Parameters:

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'cask/ci/runner_matrix.rb', line 121

def self.filter_runners(cask)
  filtered_runners = T.let({}, T::Hash[Runner, Float])
  if cask.supports_macos?
    # Skip macOS if no runner satisfies the cask's min/max macOS requirements.
    macos_requirements = [cask.depends_on.macos, cask.depends_on.maximum_macos]
                         .compact
                         .select(&:version_specified?)

    filtered_runners = if macos_requirements.empty?
      MACOS_RUNNERS.dup
    else
      MACOS_RUNNERS.select do |runner, _|
        macos_version = MacOSVersion.from_symbol(runner.fetch(:symbol).to_sym)
        macos_requirements.all? { |requirement| requirement.allows?(macos_version) }
      end
    end

    if filtered_runners.any?
      macos_archs = architectures(cask:, os: :macos)
      filtered_runners.select! do |runner, _|
        macos_archs.include?(runner.fetch(:arch))
      end
    end
  end

  if cask.supports_linux?
    linux_archs = architectures(cask:, os: :linux)
    filtered_runners.merge!(LINUX_RUNNERS.select do |runner, _|
      linux_archs.include?(runner.fetch(:arch))
    end)
  end

  # A cask that is disabled doesn't need to be tested
  filtered_runners.reject do |runner, _|
    tag = ::Utils::Bottles::Tag.new(system: runner.fetch(:symbol).to_sym, arch: runner.fetch(:arch).to_sym)
    cask.refresh_for_tag(tag) { cask.disabled? }
  end
end

.generate(default_tap, cask_names, added_casks:, labels:, skip_install:, new_cask:) ⇒ Array<Hash{Symbol => String, Boolean, Array<String>, Hash{Symbol => String}}>

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.

Parameters:

Returns:



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
110
111
112
113
114
115
116
117
118
# File 'cask/ci/runner_matrix.rb', line 45

def self.generate(default_tap, cask_names, added_casks:, labels:, skip_install:, new_cask:)
  require "cask/cask_loader"

  return [] if labels.include?("ci-syntax-only")

  check_size!(cask_names.size)
  skip_install ||= labels.include?("ci-skip-install")
  audit_exceptions = {
    "ci-skip-homepage"         => %w[homepage_https_availability homepage_domain_age],
    "ci-skip-livecheck"        => %w[hosting_with_livecheck livecheck_https_availability livecheck_version
                                     min_os],
    "ci-skip-livecheck-min-os" => %w[min_os],
    "ci-skip-repository"       => %w[github_repository github_prerelease_version
                                     gitlab_repository gitlab_prerelease_version
                                     forgejo_repository forgejo_prerelease_version bitbucket_repository],
    "ci-skip-self-submission"  => %w[self_submission],
    "ci-skip-token"            => %w[token_valid token_bad_words token_conflicts],
  }.slice(*labels).values.flatten.uniq
  jobs = cask_names.flat_map do |name|
    tap_name, _, cask_token = name.rpartition("/")
    tap = tap_name.empty? ? default_tap : Tap.fetch(tap_name)
    path = CaskLoader.find_cask_in_tap(cask_token, tap).relative_path_from(tap.path)

    audit_args = ["--online"]
    added = new_cask || added_casks.include?("#{tap.name}/#{cask_token}") ||
            (tap == default_tap && added_casks.include?(cask_token))
    audit_args << "--new" if added

    cask = CaskLoader.from_tap_path(tap.path/path)

    runners = runners(cask:)
    puts "::warning file=#{path}::No CI runner supports this cask, so it will not be tested." if runners.empty?

    # `macos-15` intermittently fails `signing` on notarized artifacts that other
    # macOS runners accept, e.g. https://github.com/Homebrew/homebrew-cask/pull/294364,
    # so skip it there when another macOS runner audits the same URL.
    macos_urls = runners.reject { |runner| runner.fetch(:symbol) == :linux }.to_h do |runner|
      tag = ::Utils::Bottles::Tag.new(system: runner.fetch(:symbol).to_sym, arch: runner.fetch(:arch).to_sym)
      [runner.fetch(:symbol), cask.refresh_for_tag(tag) { cask.url.to_s }]
    end
    skip_sequoia_signing = macos_urls.except(:sequoia).value?(macos_urls[:sequoia])

    runners.map do |runner|
      runner_audit_exceptions = audit_exceptions.dup
      runner_audit_exceptions << "signing" if skip_sequoia_signing && runner.fetch(:symbol) == :sequoia
      runner_audit_args = audit_args.dup
      runner_audit_args << "--except" << runner_audit_exceptions.join(",") if runner_audit_exceptions.any?

      runner_output = {
        name:         "test #{cask_token} (#{runner.fetch(:name)}, #{runner.fetch(:arch)})",
        tap:          tap.name,
        cask:         {
          token: cask_token,
          path:  "./#{path}",
        },
        audit_args:   runner_audit_args,
        fetch_args:   [],
        skip_install:,
        runner:       runner.fetch(:name),
      }

      if runner.fetch(:symbol) == :linux
        runner_output[:container] = {
          image:   "ghcr.io/homebrew/brew:main",
          options: "--user=linuxbrew",
        }
      end

      runner_output
    end
  end
  check_size!(jobs.size)
  jobs
end

.labels(pr_url) ⇒ Array<String>

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.

Parameters:

Returns:



29
30
31
32
33
# File 'cask/ci/runner_matrix.rb', line 29

def self.labels(pr_url)
  return [] unless pr_url

  GitHub::API.open_rest(pr_url).fetch("labels").map { |label| label.fetch("name") }
end

.random_runner(available_runners = MACOS_RUNNERS) ⇒ Runner

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.

Parameters:

  • available_runners (Hash{Runner => Float}) (defaults to: MACOS_RUNNERS)

Returns:



199
200
201
202
203
204
# File 'cask/ci/runner_matrix.rb', line 199

def self.random_runner(available_runners = MACOS_RUNNERS)
  max_runner = available_runners.max_by { |(_, weight)| rand ** (1.0 / weight) }
  raise "unexpected nil max_runner" unless max_runner

  max_runner.first
end

.runners(cask:) ⇒ Array<Runner>

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.

Parameters:

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'cask/ci/runner_matrix.rb', line 161

def self.runners(cask:)
  filtered_runners = filter_runners(cask)

  filtered_macos_found = filtered_runners.keys.any? do |runner|
    cask.to_hash_with_variations["variations"].key?(runner.fetch(:symbol).to_sym)
  end

  # If the cask varies on a macOS version, test it on every possible macOS version.
  return filtered_runners.keys if filtered_macos_found

  macos_runners, linux_runners = filtered_runners.partition do |runner, _|
    runner.fetch(:symbol) != :linux
  end
  selected_runners = macos_runners.any? ? [random_runner(macos_runners.to_h)] : []
  selected_runners + linux_runners.map(&:first)
end