2020-04-20 10:17:42 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cli/parser"
|
|
|
|
require "bintray"
|
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module_function
|
|
|
|
|
|
|
|
def pr_upload_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
|
|
|
`pr-upload` [<options>]
|
|
|
|
|
|
|
|
Apply the bottle commit and publish bottles to Bintray.
|
|
|
|
EOS
|
|
|
|
switch "--no-publish",
|
|
|
|
description: "Apply the bottle commit and upload the bottles, but don't publish them."
|
2020-07-06 17:41:07 +02:00
|
|
|
switch "--keep-old",
|
|
|
|
description: "If the formula specifies a rebuild version, " \
|
|
|
|
"attempt to preserve its value in the generated DSL."
|
2020-06-25 12:01:52 -04:00
|
|
|
switch "-n", "--dry-run",
|
2020-04-20 10:17:42 +02:00
|
|
|
description: "Print what would be done rather than doing it."
|
2020-07-02 00:11:55 +10:00
|
|
|
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."
|
2020-06-25 12:01:52 -04:00
|
|
|
flag "--bintray-org=",
|
|
|
|
description: "Upload to the specified Bintray organisation (default: `homebrew`)."
|
|
|
|
flag "--root-url=",
|
|
|
|
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
|
2020-06-22 00:21:22 +10:00
|
|
|
switch :verbose
|
|
|
|
switch :debug
|
2020-04-20 10:17:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-26 19:03:02 +10:00
|
|
|
def check_bottled_formulae(json_files)
|
2020-07-26 21:46:37 +10:00
|
|
|
hashes = json_files.reduce({}) do |hash, json|
|
|
|
|
hash.deep_merge(JSON.parse(IO.read(json)))
|
|
|
|
end
|
|
|
|
|
|
|
|
hashes.each do |name, hash|
|
2020-07-26 19:03:02 +10:00
|
|
|
formula_path = HOMEBREW_REPOSITORY/hash["formula"]["path"]
|
2020-07-27 13:13:56 -07:00
|
|
|
formula_version = Formulary.factory(formula_path).version
|
2020-07-26 19:03:02 +10:00
|
|
|
bottle_version = Version.new hash["formula"]["pkg_version"]
|
2020-07-26 21:46:37 +10:00
|
|
|
next if formula_version == bottle_version
|
|
|
|
|
|
|
|
odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!"
|
2020-07-26 19:03:02 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-20 10:17:42 +02:00
|
|
|
def pr_upload
|
2020-07-23 01:22:25 +02:00
|
|
|
args = pr_upload_args.parse
|
2020-04-20 10:17:42 +02:00
|
|
|
|
|
|
|
bintray_org = args.bintray_org || "homebrew"
|
|
|
|
bintray = Bintray.new(org: bintray_org)
|
|
|
|
|
2020-07-26 19:03:02 +10:00
|
|
|
json_files = Dir["*.json"]
|
|
|
|
odie "No JSON files found in the current working directory" if json_files.empty?
|
|
|
|
|
2020-04-20 10:31:59 -07:00
|
|
|
bottle_args = ["bottle", "--merge", "--write"]
|
2020-06-22 00:21:22 +10:00
|
|
|
bottle_args << "--verbose" if args.verbose?
|
|
|
|
bottle_args << "--debug" if args.debug?
|
2020-07-06 17:41:07 +02:00
|
|
|
bottle_args << "--keep-old" if args.keep_old?
|
2020-04-20 10:31:59 -07:00
|
|
|
bottle_args << "--root-url=#{args.root_url}" if args.root_url
|
2020-07-26 19:03:02 +10:00
|
|
|
bottle_args += json_files
|
2020-04-20 10:31:59 -07:00
|
|
|
|
2020-04-20 10:17:42 +02:00
|
|
|
if args.dry_run?
|
2020-04-20 10:31:59 -07:00
|
|
|
puts "brew #{bottle_args.join " "}"
|
2020-07-26 21:46:37 +10:00
|
|
|
puts "Upload bottles described by these JSON files to Bintray:\n #{json_files.join("\n ")}"
|
2020-04-20 10:17:42 +02:00
|
|
|
else
|
2020-07-26 19:03:02 +10:00
|
|
|
check_bottled_formulae(json_files)
|
2020-07-23 01:20:31 +02:00
|
|
|
safe_system HOMEBREW_BREW_FILE, *bottle_args
|
2020-07-26 19:03:02 +10:00
|
|
|
bintray.upload_bottle_json(json_files,
|
2020-07-02 00:11:55 +10:00
|
|
|
publish_package: !args.no_publish?,
|
|
|
|
warn_on_error: args.warn_on_upload_failure?)
|
2020-04-20 10:17:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|