2024-03-21 08:13:35 -07:00
|
|
|
# typed: strict
|
2020-07-06 22:19:17 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
require "abstract_command"
|
2024-08-03 17:44:39 -04:00
|
|
|
require "tap"
|
|
|
|
require "utils/bottles"
|
2020-07-06 22:19:17 +02:00
|
|
|
require "utils/github"
|
|
|
|
|
|
|
|
module Homebrew
|
2024-03-21 08:13:35 -07:00
|
|
|
module DevCmd
|
|
|
|
class DispatchBuildBottle < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
Build bottles for these formulae with GitHub Actions.
|
|
|
|
EOS
|
|
|
|
flag "--tap=",
|
|
|
|
description: "Target tap repository (default: `homebrew/core`)."
|
|
|
|
flag "--timeout=",
|
|
|
|
description: "Build timeout (in minutes, default: 60)."
|
|
|
|
flag "--issue=",
|
|
|
|
description: "If specified, post a comment to this issue number if the job fails."
|
|
|
|
comma_array "--macos",
|
|
|
|
description: "macOS version (or comma-separated list of versions) the bottle should be built for."
|
|
|
|
flag "--workflow=",
|
|
|
|
description: "Dispatch specified workflow (default: `dispatch-build-bottle.yml`)."
|
|
|
|
switch "--upload",
|
|
|
|
description: "Upload built bottles."
|
|
|
|
switch "--linux",
|
2025-03-25 11:03:37 +08:00
|
|
|
description: "Dispatch bottle for Linux x86_64 (using GitHub runners)."
|
|
|
|
switch "--linux-arm64",
|
|
|
|
description: "Dispatch bottle for Linux arm64 (using GitHub runners)."
|
2024-03-21 08:13:35 -07:00
|
|
|
switch "--linux-self-hosted",
|
2025-03-25 11:03:37 +08:00
|
|
|
description: "Dispatch bottle for Linux x86_64 (using self-hosted runner)."
|
2024-03-21 08:13:35 -07:00
|
|
|
switch "--linux-wheezy",
|
|
|
|
description: "Use Debian Wheezy container for building the bottle on Linux."
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
conflicts "--linux", "--linux-self-hosted"
|
|
|
|
named_args :formula, min: 1
|
|
|
|
end
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
sig { override.void }
|
|
|
|
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"
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
runners = []
|
2020-12-07 13:20:01 +00:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
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
|
2022-06-14 00:48:25 +01:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
if arch.present? && arch != :x86_64
|
|
|
|
"#{os}-#{arch}"
|
|
|
|
else
|
|
|
|
os.to_s
|
|
|
|
end
|
|
|
|
end
|
2021-10-24 05:13:11 +01:00
|
|
|
end
|
2020-11-29 22:36:06 +01:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
if args.linux?
|
|
|
|
runners << "ubuntu-22.04"
|
|
|
|
elsif args.linux_self_hosted?
|
|
|
|
runners << "linux-self-hosted-1"
|
2021-10-24 05:13:11 +01:00
|
|
|
end
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2025-03-25 11:03:37 +08:00
|
|
|
runners << "ubuntu-22.04-arm" if args.linux_arm64?
|
|
|
|
|
|
|
|
if runners.empty?
|
|
|
|
raise UsageError, "Must specify `--macos`, `--linux`, `--linux-arm64`, or `--linux-self-hosted` option."
|
|
|
|
end
|
2022-06-14 00:48:25 +01:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
args.named.to_resolved_formulae.each do |formula|
|
|
|
|
# Required inputs
|
|
|
|
inputs = {
|
|
|
|
runner: runners.join(","),
|
|
|
|
formula: formula.name,
|
|
|
|
}
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
# 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?
|
2020-07-06 22:19:17 +02:00
|
|
|
|
2024-03-21 08:13:35 -07:00
|
|
|
ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for #{runners.join(", ")}"
|
|
|
|
GitHub.workflow_dispatch_event(user, repo, workflow, ref, **inputs)
|
|
|
|
end
|
|
|
|
end
|
2020-07-06 22:19:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|