Class: Homebrew::DevCmd::DispatchBuildBottle

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/dispatch-build-bottle.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.

Raises:



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
80
81
82
83
84
85
86
87
88
89
# File 'dev-cmd/dispatch-build-bottle.rb', line 38

def run
  tap = Tap.fetch(args.tap || CoreTap.instance.name)
  user, repo = tap.full_name.split("/")
  ref = "master"
  workflow = args.workflow || "dispatch-build-bottle.yml"

  runners = []

  if (macos = args.macos&.compact_blank) && macos.present?
    runners += macos.map do |element|
      # We accept runner name syntax (11-arm64) or bottle syntax (arm64_big_sur)
      os, arch = element.then do |s|
        tag = Utils::Bottles::Tag.from_symbol(s.to_sym)
        [tag.to_macos_version, tag.arch]
      rescue ArgumentError, MacOSVersion::Error
        os, arch = s.split("-", 2)
        [MacOSVersion.new(os), arch&.to_sym]
      end

      if arch.present? && arch != :x86_64
        "#{os}-#{arch}"
      else
        os.to_s
      end
    end
  end

  if args.linux?
    runners << "ubuntu-22.04"
  elsif args.linux_self_hosted?
    runners << "linux-self-hosted-1"
  end

  raise UsageError, "Must specify `--macos`, `--linux` or `--linux-self-hosted` option." if runners.empty?

  args.named.to_resolved_formulae.each do |formula|
    # Required inputs
    inputs = {
      runner:  runners.join(","),
      formula: formula.name,
    }

    # Optional inputs
    # These cannot be passed as nil to GitHub API
    inputs[:timeout] = args.timeout if args.timeout
    inputs[:issue] = args.issue if args.issue
    inputs[:upload] = args.upload?

    ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for #{runners.join(", ")}"
    GitHub.workflow_dispatch_event(user, repo, workflow, ref, **inputs)
  end
end