From ebfd308241f679ecf2f9ccadb138fcc2622f7778 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sun, 26 Jul 2020 19:03:02 +1000 Subject: [PATCH 1/2] pr-upload: ensure bottle and formula version match --- Library/Homebrew/dev-cmd/pr-upload.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index 2d27d6f5a5..3e50e39ddd 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -32,26 +32,40 @@ module Homebrew end end + def check_bottled_formulae(json_files) + json_files.reduce({}) { |hash, json| hash.deep_merge(JSON.parse(IO.read(json))) }.each do |name, hash| + formula_path = HOMEBREW_REPOSITORY/hash["formula"]["path"] + formula_version = Formulary::FormulaLoader.new(name, formula_path).get_formula("stable").version + bottle_version = Version.new hash["formula"]["pkg_version"] + if formula_version != bottle_version + odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!" + end + end + end + def pr_upload args = pr_upload_args.parse bintray_org = args.bintray_org || "homebrew" bintray = Bintray.new(org: bintray_org) + json_files = Dir["*.json"] + odie "No JSON files found in the current working directory" if json_files.empty? + bottle_args = ["bottle", "--merge", "--write"] bottle_args << "--verbose" if args.verbose? bottle_args << "--debug" if args.debug? bottle_args << "--keep-old" if args.keep_old? bottle_args << "--root-url=#{args.root_url}" if args.root_url - odie "No JSON files found in the current working directory" if Dir["*.json"].empty? - bottle_args += Dir["*.json"] + bottle_args += json_files if args.dry_run? puts "brew #{bottle_args.join " "}" puts "Upload bottles described by these JSON files to Bintray:\n #{Dir["*.json"].join("\n ")}" else + check_bottled_formulae(json_files) safe_system HOMEBREW_BREW_FILE, *bottle_args - bintray.upload_bottle_json(Dir["*.json"], + bintray.upload_bottle_json(json_files, publish_package: !args.no_publish?, warn_on_error: args.warn_on_upload_failure?) end From 80b62d8c2c3a3b42bf013655aaa27f79edb736f8 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sun, 26 Jul 2020 21:46:37 +1000 Subject: [PATCH 2/2] pr-upload: style tweaks Co-authored-by: Dawid Dziurla Co-authored-by: Mike McQuaid --- Library/Homebrew/dev-cmd/pr-upload.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index 3e50e39ddd..c40f355db8 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -33,13 +33,17 @@ module Homebrew end def check_bottled_formulae(json_files) - json_files.reduce({}) { |hash, json| hash.deep_merge(JSON.parse(IO.read(json))) }.each do |name, hash| + hashes = json_files.reduce({}) do |hash, json| + hash.deep_merge(JSON.parse(IO.read(json))) + end + + hashes.each do |name, hash| formula_path = HOMEBREW_REPOSITORY/hash["formula"]["path"] formula_version = Formulary::FormulaLoader.new(name, formula_path).get_formula("stable").version bottle_version = Version.new hash["formula"]["pkg_version"] - if formula_version != bottle_version - odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!" - end + next if formula_version == bottle_version + + odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!" end end @@ -61,7 +65,7 @@ module Homebrew if args.dry_run? puts "brew #{bottle_args.join " "}" - puts "Upload bottles described by these JSON files to Bintray:\n #{Dir["*.json"].join("\n ")}" + puts "Upload bottles described by these JSON files to Bintray:\n #{json_files.join("\n ")}" else check_bottled_formulae(json_files) safe_system HOMEBREW_BREW_FILE, *bottle_args