Class: Homebrew::DevCmd::GenerateCaskCiMatrix Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::GenerateCaskCiMatrix
- 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
Constant Summary collapse
- 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- X86_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-intel", arch: :intel } => 1.0, }.freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], Float])
- X86_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, }.freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], Float])
- ARM_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.
T.let({ { symbol: :sonoma, name: "macos-14", arch: :arm } => 0.0, { symbol: :sequoia, name: "macos-15", arch: :arm } => 0.0, { symbol: :tahoe, name: "macos-26", arch: :arm } => 1.0, }.freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], Float])
- ARM_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: OS::LINUX_CI_ARM_RUNNER, arch: :arm } => 1.0, }.freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], Float])
- 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.
T.let(X86_MACOS_RUNNERS.merge(ARM_MACOS_RUNNERS).freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], 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(X86_LINUX_RUNNERS.merge(ARM_LINUX_RUNNERS).freeze, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], 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[T::Hash[Symbol, T.any(Symbol, String)], Float])
Instance Method Summary collapse
- #args ⇒ Homebrew::DevCmd::GenerateCaskCiMatrix::Args private
- #filter_runners(cask) ⇒ Hash{Hash{Symbol => Symbol, String} => Float} private
- #run ⇒ void private
- #runner_arch_pairs(runners:, multi_os:) ⇒ Array<Array<(Hash{Symbol => Symbol, String}, [Symbol, String], Boolean)>> private
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_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #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 |
#filter_runners(cask) ⇒ Hash{Hash{Symbol => Symbol, String} => 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.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 136 def filter_runners(cask) filtered_runners = T.let({}, T::Hash[T::Hash[Symbol, T.any(Symbol, String)], 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 return filtered_runners unless cask.supports_linux? linux_archs = architectures(cask:, os: :linux) linux_runners = LINUX_RUNNERS.select do |runner, _| linux_archs.include?(runner.fetch(:arch)) end filtered_runners.merge(linux_runners) 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.
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 63 def run skip_install = args.skip_install? new_cask = args.new? casks = args.named if args.casks? pr_url = args.named if args.url? syntax_only = args.syntax_only? repository = ENV.fetch("GITHUB_REPOSITORY", nil) raise UsageError, "The `$GITHUB_REPOSITORY` environment variable must be set." if repository.blank? tap = T.let(Tap.fetch(repository), Tap) unless syntax_only raise UsageError, "Either `--cask` or `--url` must be specified." if !args.casks? && !args.url? raise UsageError, "Please provide a `--cask` or `--url` argument." if casks.blank? && pr_url.blank? end raise UsageError, "Only one `--url` can be specified." if pr_url&.count&.> 1 labels = if pr_url && (first_pr_url = pr_url.first) pr = GitHub::API.open_rest(first_pr_url) pr.fetch("labels").map { |l| l.fetch("name") } else [] end runner = random_runner[:name] syntax_job = { name: "tap_syntax", tap: tap.name, runner:, stable: false, } stable_syntax_job = syntax_job.merge(name: "tap_syntax (stable)", stable: true, skip_audit: true) matrix = [syntax_job, stable_syntax_job] if !syntax_only && !labels&.include?("ci-syntax-only") cask_jobs = if casks&.any? generate_matrix(tap, labels:, cask_names: casks, skip_install:, new_cask:) else generate_matrix(tap, labels:, skip_install:, new_cask:) end if cask_jobs.any? # If casks were changed, skip `audit` for whole tap. syntax_job[:skip_audit] = true # The syntax job only runs `style` at this point, which should work on Linux. # Running on macOS is currently faster though, since `homebrew/cask` and # `homebrew/core` are already tapped on macOS CI machines. # syntax_job[:runner] = "ubuntu-latest" end matrix += cask_jobs end jobs = matrix.count odie "Maximum job matrix size exceeded: #{jobs}/#{MAX_JOBS}" if jobs > MAX_JOBS [syntax_job, stable_syntax_job].each do |job| job[:name] += " (#{job[:runner]})" end puts JSON.pretty_generate(matrix) github_output = ENV.fetch("GITHUB_OUTPUT", nil) return unless github_output File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f| f.puts "matrix=#{JSON.generate(matrix)}" end end |
#runner_arch_pairs(runners:, multi_os:) ⇒ Array<Array<(Hash{Symbol => Symbol, String}, [Symbol, String], Boolean)>>
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.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 176 def runner_arch_pairs(runners:, multi_os:) macos_archs = runners.reject { |r| r.fetch(:symbol) == :linux }.map { |r| r.fetch(:arch) }.uniq linux_archs = runners.select { |r| r.fetch(:symbol) == :linux }.map { |r| r.fetch(:arch) }.uniq product_archs = macos_archs | linux_archs runners.product(product_archs).filter_map do |runner, arch| native_runner_arch = arch == runner.fetch(:arch) # we don't need to run simulated archs on Linux or macOS Sequoia # because they exist as real GitHub hosted runners next if runner.fetch(:symbol) == :linux && !native_runner_arch next if runner.fetch(:symbol) == :sequoia && !native_runner_arch # skip macOS runners simulating architectures not supported on macOS next if runner.fetch(:symbol) != :linux && !native_runner_arch && macos_archs.exclude?(arch) # if it's just a single OS test then we can just use the two real arch runners next if !native_runner_arch && !multi_os [runner, arch, native_runner_arch] end end |