diff --git a/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb b/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb new file mode 100644 index 0000000000..b95fed186e --- /dev/null +++ b/Library/Homebrew/dev-cmd/dispatch-build-bottle.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require "cli/parser" +require "utils/github" + +module Homebrew + module_function + + def dispatch_build_bottle_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `dispatch-build-bottle` [] [ ...] + + Build bottles for these formulae with GitHub Actions. + EOS + flag "--tap=", + description: "Target tap repository (default: `homebrew/core`)." + 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 to Bintray." + end + end + + def dispatch_build_bottle + args = dispatch_build_bottle_args.parse + + raise FormulaUnspecifiedError if args.named.empty? + + odie "Must specify --macos option" unless args.macos + + macos = begin + MacOS::Version.from_symbol(args.macos.to_sym) + rescue MacOSVersionError + MacOS::Version.new(args.macos) + end + + tap = Tap.fetch(args.tap || CoreTap.instance.name) + user, repo = tap.full_name.split("/") + + workflow = args.workflow || "dispatch-build-bottle.yml" + ref = "master" + + args.named.to_resolved_formulae.each do |formula| + # Required inputs + inputs = { + formula: formula.name, + macos: macos.to_s, + } + + # Optional inputs + # These cannot be passed as nil to GitHub API + inputs[:issue] = args.issue if args.issue + inputs[:upload] = args.upload?.to_s if args.upload? + + ohai "Dispatching #{tap} bottling request of formula \"#{formula.name}\" for macOS #{macos}" + GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs) + end + end +end diff --git a/Library/Homebrew/test/dev-cmd/dispatch-build-bottle_spec.rb b/Library/Homebrew/test/dev-cmd/dispatch-build-bottle_spec.rb new file mode 100644 index 0000000000..b89731e40e --- /dev/null +++ b/Library/Homebrew/test/dev-cmd/dispatch-build-bottle_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "cmd/shared_examples/args_parse" + +describe "Homebrew.dispatch_build_bottle_args" do + it_behaves_like "parseable arguments" +end diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt index 4e7367131a..cd9c60d4b0 100644 --- a/completions/internal_commands_list.txt +++ b/completions/internal_commands_list.txt @@ -27,6 +27,7 @@ configure create deps desc +dispatch-build-bottle diy doctor dr diff --git a/docs/Manpage.md b/docs/Manpage.md index ad972b3e1e..204ffac87e 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -968,6 +968,21 @@ a simple example. For the complete API, see: * `-f`, `--force`: Ignore errors for disallowed formula names and named that shadow aliases. +### `dispatch-build-bottle` [*`options`*] *`formula`* [*`formula`* ...] + +Build bottles for these formulae with GitHub Actions. + +* `--tap`: + Target tap repository (default: `homebrew/core`). +* `--issue`: + If specified, post a comment to this issue number if the job fails. +* `--macos`: + Version of macOS the bottle should be built for. +* `--workflow`: + Dispatch specified workflow (default: `dispatch-build-bottle.yml`). +* `--upload`: + Upload built bottles to Bintray. + ### `diy` [*`options`*] Automatically determine the installation prefix for non-Homebrew software. diff --git a/manpages/brew.1 b/manpages/brew.1 index f8d8da4472..69b4b2c387 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1363,6 +1363,29 @@ Generate the new formula within the given tap, specified as \fIuser\fR\fB/\fR\fI \fB\-f\fR, \fB\-\-force\fR Ignore errors for disallowed formula names and named that shadow aliases\. . +.SS "\fBdispatch\-build\-bottle\fR [\fIoptions\fR] \fIformula\fR [\fIformula\fR \.\.\.]" +Build bottles for these formulae with GitHub Actions\. +. +.TP +\fB\-\-tap\fR +Target tap repository (default: \fBhomebrew/core\fR)\. +. +.TP +\fB\-\-issue\fR +If specified, post a comment to this issue number if the job fails\. +. +.TP +\fB\-\-macos\fR +Version of macOS the bottle should be built for\. +. +.TP +\fB\-\-workflow\fR +Dispatch specified workflow (default: \fBdispatch\-build\-bottle\.yml\fR)\. +. +.TP +\fB\-\-upload\fR +Upload built bottles to Bintray\. +. .SS "\fBdiy\fR [\fIoptions\fR]" Automatically determine the installation prefix for non\-Homebrew software\. Using the output from this command, you can install your own software into the Cellar and then link it into Homebrew\'s prefix with \fBbrew link\fR\. .