Class: Homebrew::DevCmd::GenerateBottleCiMatrix Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/generate-bottle-ci-matrix.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/generate_bottle_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_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

#argsHomebrew::DevCmd::GenerateBottleCiMatrix::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_bottle_ci_matrix.rbi', line 10

def args; end

#runvoid

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:



25
26
27
28
29
30
31
32
33
34
35
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
# File 'dev-cmd/generate-bottle-ci-matrix.rb', line 25

def run
  runners = args.runners.to_a.map(&:strip).reject(&:empty?)
  raise UsageError, "`--runners` must specify at least one build runner." if runners.empty?

  github_run_id = ENV.fetch("GITHUB_RUN_ID") do
    raise UsageError, "The `$GITHUB_RUN_ID` environment variable must be set."
  end
  formula = args.named.to_formulae.fetch(0)
  matrix = runners.map do |runner|
    macos_runner_parts = runner.split("-", 2) if runner.match?(/\A\d+(?:\.\d+)?(?:-(?:arm64|x86_64))?\z/)
    bottle_tag = if (runner.start_with?("ubuntu-") && runner.end_with?("-arm")) ||
                    runner.match?(/\Alinux-arm64(?:\z|-)/)
      Utils::Bottles.tag(:arm64_linux)
    elsif runner.start_with?("ubuntu", "linux")
      Utils::Bottles.tag(:x86_64_linux)
    elsif macos_runner_parts
      Utils::Bottles::Tag.new(
        system: MacOSVersion.new(macos_runner_parts.fetch(0)).to_sym,
        arch:   macos_runner_parts.fetch(1, "x86_64").to_sym,
      )
    end
    if bottle_tag && formula.bottle_specification.tag?(bottle_tag, no_older_versions: true)
      ofail "#{formula.name} already has a bottle for #{bottle_tag}!"
    end

    if macos_runner_parts
      {
        runner:  "#{macos_runner_parts.fetch(0)}-#{macos_runner_parts.fetch(1, "x86_64")}-" \
                 "#{github_run_id}-dispatch",
        cleanup: false,
      }
    elsif runner.start_with?("ubuntu-")
      {
        runner:,
        container: {
          image:   "ghcr.io/homebrew/brew:main",
          options: "--user=linuxbrew",
        },
        workdir:   "/github/home",
        cleanup:   false,
      }
    elsif runner.match?(/\Alinux-(?:arm64|x86_64)\z/)
      { runner: "#{runner}-#{github_run_id}-dispatch", cleanup: false }
    else
      { runner:, cleanup: true }
    end
  end
  puts JSON.pretty_generate(matrix)

  return unless (github_output = ENV.fetch("GITHUB_OUTPUT", nil))

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