From 204e56d01ec309be343f8d1185fb3ade77496ec8 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Thu, 2 Jul 2020 00:11:55 +1000 Subject: [PATCH] pr-pull, pr-upload: add --warn-on-upload-failure --- Library/Homebrew/bintray.rb | 24 ++++++++++++++++++------ Library/Homebrew/dev-cmd/pr-pull.rb | 4 ++++ Library/Homebrew/dev-cmd/pr-upload.rb | 7 ++++++- docs/Manpage.md | 4 ++++ manpages/brew-cask.1 | 2 +- manpages/brew.1 | 10 +++++++++- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/bintray.rb b/Library/Homebrew/bintray.rb index 1800316c4c..cb2966ca0d 100644 --- a/Library/Homebrew/bintray.rb +++ b/Library/Homebrew/bintray.rb @@ -50,12 +50,15 @@ class Bintray result end - def publish(repo:, package:, version:, file_count:) + def publish(repo:, package:, version:, file_count:, warn_on_error: false) url = "#{API_URL}/content/#{@bintray_org}/#{repo}/#{package}/#{version}/publish" result = open_api url, "--request", "POST", "--fail" json = JSON.parse(result.stdout) if file_count.present? && json["files"] != file_count - raise "Bottle publish failed: expected #{file_count} bottles, but published #{json["files"]} instead." + message = "Bottle publish failed: expected #{file_count} bottles, but published #{json["files"]} instead." + raise message unless warn_on_error + + opoo message end odebug "Published #{json["files"]} bottles" @@ -143,7 +146,7 @@ class Bintray end end - def upload_bottle_json(json_files, publish_package: false) + def upload_bottle_json(json_files, publish_package: false, warn_on_error: false) bottles_hash = json_files.reduce({}) do |hash, json_file| hash.deep_merge(JSON.parse(IO.read(json_file))) end @@ -161,14 +164,19 @@ class Bintray odebug "Checking remote file #{@bintray_org}/#{bintray_repo}/#{filename}" if file_published? repo: bintray_repo, remote_file: filename - raise Error, <<~EOS - #{filename} is already published. + already_published = "#{filename} is already published." + failed_message = <<~EOS + #{already_published} Please remove it manually from: https://bintray.com/#{@bintray_org}/#{bintray_repo}/#{bintray_package}/view#files Or run: curl -X DELETE -u $HOMEBREW_BINTRAY_USER:$HOMEBREW_BINTRAY_KEY \\ https://api.bintray.com/content/#{@bintray_org}/#{bintray_repo}/#{filename} EOS + raise Error, failed_message unless warn_on_error + + opoo already_published + next end if !formula_packaged[formula_name] && !package_exists?(repo: bintray_repo, package: bintray_package) @@ -189,7 +197,11 @@ class Bintray bottle_count = bottle_hash["bottle"]["tags"].length odebug "Publishing #{@bintray_org}/#{bintray_repo}/#{bintray_package}/#{version}" - publish repo: bintray_repo, package: bintray_package, version: version, file_count: bottle_count + publish(repo: bintray_repo, + package: bintray_package, + version: version, + file_count: bottle_count, + warn_on_error: warn_on_error) end end end diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index db24c2c1f6..8d7c783e3c 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -33,6 +33,9 @@ module Homebrew switch "--resolve", description: "When a patch fails to apply, leave in progress and allow user to resolve, "\ "instead of aborting." + switch "--warn-on-upload-failure", + description: "Warn instead of raising an error if the bottle upload fails. "\ + "Useful for repairing bottle uploads that previously failed." flag "--workflow=", description: "Retrieve artifacts from the specified workflow (default: `tests.yml`)." flag "--artifact=", @@ -258,6 +261,7 @@ module Homebrew upload_args << "--verbose" if Homebrew.args.verbose? upload_args << "--no-publish" if args.no_publish? upload_args << "--dry-run" if args.dry_run? + upload_args << "--warn-on-upload-failure" if args.warn_on_upload_failure? upload_args << "--root_url=#{args.root_url}" if args.root_url upload_args << "--bintray-org=#{bintray_org}" safe_system HOMEBREW_BREW_FILE, *upload_args diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index 276f6071b7..39dfd145ba 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -17,6 +17,9 @@ module Homebrew description: "Apply the bottle commit and upload the bottles, but don't publish them." switch "-n", "--dry-run", description: "Print what would be done rather than doing it." + switch "--warn-on-upload-failure", + description: "Warn instead of raising an error if the bottle upload fails. "\ + "Useful for repairing bottle uploads that previously failed." flag "--bintray-org=", description: "Upload to the specified Bintray organisation (default: `homebrew`)." flag "--root-url=", @@ -48,7 +51,9 @@ module Homebrew if args.dry_run? puts "Upload bottles described by these JSON files to Bintray:\n #{Dir["*.json"].join("\n ")}" else - bintray.upload_bottle_json Dir["*.json"], publish_package: !args.no_publish? + bintray.upload_bottle_json(Dir["*.json"], + publish_package: !args.no_publish?, + warn_on_error: args.warn_on_upload_failure?) end end end diff --git a/docs/Manpage.md b/docs/Manpage.md index a95886ff5e..2709a17839 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -903,6 +903,8 @@ repository. Do not warn if pulling to a branch besides master (useful for testing). * `--resolve`: When a patch fails to apply, leave in progress and allow user to resolve, instead of aborting. +* `--warn-on-upload-failure`: + Warn instead of raising an error if the bottle upload fails. Useful for repairing bottle uploads that previously failed. * `--workflow`: Retrieve artifacts from the specified workflow (default: `tests.yml`). * `--artifact`: @@ -924,6 +926,8 @@ Apply the bottle commit and publish bottles to Bintray. Apply the bottle commit and upload the bottles, but don't publish them. * `-n`, `--dry-run`: Print what would be done rather than doing it. +* `--warn-on-upload-failure`: + Warn instead of raising an error if the bottle upload fails. Useful for repairing bottle uploads that previously failed. * `--bintray-org`: Upload to the specified Bintray organisation (default: `homebrew`). * `--root-url`: diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index f250696a66..f00c80f3ed 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "June 2020" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "July 2020" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index c65e7cf4ed..a653c4df12 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "June 2020" "Homebrew" "brew" +.TH "BREW" "1" "July 2020" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The Missing Package Manager for macOS @@ -1176,6 +1176,10 @@ Do not warn if pulling to a branch besides master (useful for testing)\. When a patch fails to apply, leave in progress and allow user to resolve, instead of aborting\. . .TP +\fB\-\-warn\-on\-upload\-failure\fR +Warn instead of raising an error if the bottle upload fails\. Useful for repairing bottle uploads that previously failed\. +. +.TP \fB\-\-workflow\fR Retrieve artifacts from the specified workflow (default: \fBtests\.yml\fR)\. . @@ -1211,6 +1215,10 @@ Apply the bottle commit and upload the bottles, but don\'t publish them\. Print what would be done rather than doing it\. . .TP +\fB\-\-warn\-on\-upload\-failure\fR +Warn instead of raising an error if the bottle upload fails\. Useful for repairing bottle uploads that previously failed\. +. +.TP \fB\-\-bintray\-org\fR Upload to the specified Bintray organisation (default: \fBhomebrew\fR)\. .