dev-cmd/pr-publish: support new workflow inputs

This allows us to use the new options without needing to use the GitHub
UI.
This commit is contained in:
Carlo Cabrera 2023-03-28 21:58:18 +08:00
parent 834e4c98fc
commit 76833dfe40
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -16,6 +16,8 @@ module Homebrew
Publish bottles for a pull request with GitHub Actions.
Requires write access to the repository.
EOS
switch "--commit-bottles-to-pr-branch",
description: "Push bottle commits to the pull request branch."
switch "--autosquash",
description: "If supported on the target tap, automatically reformat and reword commits " \
"to our preferred format."
@ -23,8 +25,10 @@ module Homebrew
description: "Skip automatically reformatting and rewording commits in the pull request " \
"to the preferred format, even if supported on the target tap.",
replacement: "`--autosquash` to opt in"
switch "--large-runner",
description: "Run the upload job on a large runner."
flag "--branch=",
description: "Branch to publish to (default: `master`)."
description: "Branch to use the workflow from (default: `master`)."
flag "--message=",
depends_on: "--autosquash",
description: "Message to include when autosquashing revision bumps, deletions, and rebuilds."
@ -48,22 +52,27 @@ module Homebrew
workflow = args.workflow || "publish-commit-bottles.yml"
ref = args.branch || "master"
extra_args = []
extra_args << "--autosquash" if args.autosquash?
extra_args << "--message='#{args.message}'" if args.message.presence
dispatch_args = extra_args.join " "
inputs = {
commit_bottles_to_pr_branch: args.commit_bottles_to_pr_branch?,
autosquash: args.autosquash?,
large_runner: args.large_runner?,
}
inputs[:message] = args.message if args.message.presence
args.named.uniq.each do |arg|
arg = "#{tap.default_remote}/pull/#{arg}" if arg.to_i.positive?
url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
_, user, repo, issue = *url_match
odie "Not a GitHub pull request: #{arg}" unless issue
inputs[:pull_request] = issue
if args.tap.present? && !T.must("#{user}/#{repo}".casecmp(tap.full_name)).zero?
odie "Pull request URL is for #{user}/#{repo} but `--tap=#{tap.full_name}` was specified!"
end
ohai "Dispatching #{tap} pull request ##{issue}"
GitHub.workflow_dispatch_event(user, repo, workflow, ref, pull_request: issue, args: dispatch_args)
GitHub.workflow_dispatch_event(user, repo, workflow, ref, inputs)
end
end
end