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- 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: :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])
- 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[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
- #runners(cask:) ⇒ Array<Hash{Symbol => Symbol, String}> 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_cannot_install, #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.
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 159 160 161 162 163 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 127 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 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 |
#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.
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 119 120 121 122 123 124 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 54 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 |
#runners(cask:) ⇒ Array<Hash{Symbol => 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.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'dev-cmd/generate-cask-ci-matrix.rb', line 166 def 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 |