Port Homebrew::DevCmd::PrUpload
This commit is contained in:
parent
dc062bea52
commit
6d362ccb3b
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "formula"
|
||||
require "github_packages"
|
||||
@ -8,11 +9,9 @@ require "github_releases"
|
||||
require "extend/hash/deep_merge"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def pr_upload_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module DevCmd
|
||||
class PrUpload < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Apply the bottle commit and publish bottles to a host.
|
||||
EOS
|
||||
@ -41,54 +40,9 @@ module Homebrew
|
||||
|
||||
named_args :none
|
||||
end
|
||||
end
|
||||
|
||||
def check_bottled_formulae!(bottles_hash)
|
||||
bottles_hash.each do |name, bottle_hash|
|
||||
formula_path = HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]
|
||||
formula_version = Formulary.factory(formula_path).pkg_version
|
||||
bottle_version = PkgVersion.parse bottle_hash["formula"]["pkg_version"]
|
||||
next if formula_version == bottle_version
|
||||
|
||||
odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!"
|
||||
end
|
||||
end
|
||||
|
||||
def github_releases?(bottles_hash)
|
||||
@github_releases ||= bottles_hash.values.all? do |bottle_hash|
|
||||
root_url = bottle_hash["bottle"]["root_url"]
|
||||
url_match = root_url.match GitHubReleases::URL_REGEX
|
||||
_, _, _, tag = *url_match
|
||||
|
||||
tag
|
||||
end
|
||||
end
|
||||
|
||||
def github_packages?(bottles_hash)
|
||||
@github_packages ||= bottles_hash.values.all? do |bottle_hash|
|
||||
bottle_hash["bottle"]["root_url"].match? GitHubPackages::URL_REGEX
|
||||
end
|
||||
end
|
||||
|
||||
def bottles_hash_from_json_files(json_files, args)
|
||||
puts "Reading JSON files: #{json_files.join(", ")}" if args.verbose?
|
||||
|
||||
bottles_hash = json_files.reduce({}) do |hash, json_file|
|
||||
hash.deep_merge(JSON.parse(File.read(json_file)))
|
||||
end
|
||||
|
||||
if args.root_url
|
||||
bottles_hash.each_value do |bottle_hash|
|
||||
bottle_hash["bottle"]["root_url"] = args.root_url
|
||||
end
|
||||
end
|
||||
|
||||
bottles_hash
|
||||
end
|
||||
|
||||
def pr_upload
|
||||
args = pr_upload_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
json_files = Dir["*.bottle.json"]
|
||||
odie "No bottle JSON files found in the current working directory" if json_files.blank?
|
||||
bottles_hash = bottles_hash_from_json_files(json_files, args)
|
||||
@ -163,4 +117,51 @@ module Homebrew
|
||||
odie "Service specified by root_url is not recognized"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_bottled_formulae!(bottles_hash)
|
||||
bottles_hash.each do |name, bottle_hash|
|
||||
formula_path = HOMEBREW_REPOSITORY/bottle_hash["formula"]["path"]
|
||||
formula_version = Formulary.factory(formula_path).pkg_version
|
||||
bottle_version = PkgVersion.parse bottle_hash["formula"]["pkg_version"]
|
||||
next if formula_version == bottle_version
|
||||
|
||||
odie "Bottles are for #{name} #{bottle_version} but formula is version #{formula_version}!"
|
||||
end
|
||||
end
|
||||
|
||||
def github_releases?(bottles_hash)
|
||||
@github_releases ||= bottles_hash.values.all? do |bottle_hash|
|
||||
root_url = bottle_hash["bottle"]["root_url"]
|
||||
url_match = root_url.match GitHubReleases::URL_REGEX
|
||||
_, _, _, tag = *url_match
|
||||
|
||||
tag
|
||||
end
|
||||
end
|
||||
|
||||
def github_packages?(bottles_hash)
|
||||
@github_packages ||= bottles_hash.values.all? do |bottle_hash|
|
||||
bottle_hash["bottle"]["root_url"].match? GitHubPackages::URL_REGEX
|
||||
end
|
||||
end
|
||||
|
||||
def bottles_hash_from_json_files(json_files, args)
|
||||
puts "Reading JSON files: #{json_files.join(", ")}" if args.verbose?
|
||||
|
||||
bottles_hash = json_files.reduce({}) do |hash, json_file|
|
||||
hash.deep_merge(JSON.parse(File.read(json_file)))
|
||||
end
|
||||
|
||||
if args.root_url
|
||||
bottles_hash.each_value do |bottle_hash|
|
||||
bottle_hash["bottle"]["root_url"] = args.root_url
|
||||
end
|
||||
end
|
||||
|
||||
bottles_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/pr-upload"
|
||||
|
||||
RSpec.describe "brew pr-upload" do
|
||||
RSpec.describe Homebrew::DevCmd::PrUpload do
|
||||
it_behaves_like "parseable arguments"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user