brew/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb

96 lines
3.1 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# frozen_string_literal: true
require "cli/parser"
require "utils/github"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def dispatch_build_bottle_args
Homebrew::CLI::Parser.new 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."
flag "--macos=",
description: "Version of macOS the bottle should be built for."
flag "--workflow=",
description: "Dispatch specified workflow (default: `dispatch-build-bottle.yml`)."
switch "--upload",
description: "Upload built bottles."
2021-03-03 15:55:47 +01:00
switch "--linux",
description: "Dispatch bottle for Linux (using GitHub runners)."
switch "--linux-self-hosted",
description: "Dispatch bottle for Linux (using self-hosted runner)."
switch "--linux-wheezy",
description: "Use Debian Wheezy container for building the bottle on Linux."
2020-11-12 10:40:41 -05:00
conflicts "--macos", "--linux", "--linux-self-hosted"
2021-01-10 14:26:40 -05:00
named_args :formula, min: 1
end
end
def dispatch_build_bottle
args = dispatch_build_bottle_args.parse
2021-03-03 15:55:47 +01:00
tap = Tap.fetch(args.tap || CoreTap.instance.name)
user, repo = tap.full_name.split("/")
ref = "master"
workflow = args.workflow || "dispatch-build-bottle.yml"
2021-03-03 15:55:47 +01:00
# Ensure we dispatch the bottle in homebrew/homebrew-core
# TODO: remove when core taps are merged
repo.gsub!("linux", "home") unless args.tap
runner = if (macos = args.macos)
# We accept runner name syntax (11-arm64) or bottle syntax (arm64_big_sur)
os, arch = macos.yield_self do |s|
tag = Utils::Bottles::Tag.from_symbol(s.to_sym)
[tag.to_macos_version, tag.arch]
rescue ArgumentError, MacOSVersionError
os, arch = s.split("-", 2)
[MacOS::Version.new(os), arch&.to_sym]
2021-03-03 15:55:47 +01:00
end
if arch.present? && arch != :x86_64
"#{os}-#{arch}"
2021-03-03 15:55:47 +01:00
else
os.to_s
2021-03-03 15:55:47 +01:00
end
elsif args.linux?
"ubuntu-latest"
elsif args.linux_self_hosted?
"linux-self-hosted-1"
2021-03-03 15:55:47 +01:00
else
raise UsageError, "Must specify --macos or --linux or --linux-self-hosted option"
2021-03-03 15:55:47 +01:00
end
args.named.to_resolved_formulae.each do |formula|
# Required inputs
inputs = {
runner: runner,
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?.to_s if args.upload?
inputs[:wheezy] = args.linux_wheezy?.to_s if args.linux_wheezy?
ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for #{runner}"
GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs)
end
end
end