mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
pr-pull: dupe logic moved to mirror and pr-upload
This commit is contained in:
parent
8c21e8b2db
commit
17c20c0e11
@ -72,7 +72,7 @@ class Bintray
|
||||
status_code.start_with?("2")
|
||||
end
|
||||
|
||||
def mirror_formula(formula, repo: "mirror")
|
||||
def mirror_formula(formula, repo: "mirror", publish_package: false)
|
||||
package = Utils::Bottles::Bintray.package formula.name
|
||||
|
||||
create_package(repo: repo, package: package) unless package_exists?(repo: repo, package: package)
|
||||
@ -93,7 +93,10 @@ class Bintray
|
||||
sha256: formula.stable.checksum,
|
||||
remote_file: filename,
|
||||
)
|
||||
publish(repo: repo, package: package, version: version)
|
||||
return destination_url unless publish_package
|
||||
|
||||
odebug "Publishing #{@bintray_org}/#{repo}/#{package}/#{version}"
|
||||
publish(repo: repo, package: package, version: version, file_count: 1)
|
||||
|
||||
destination_url
|
||||
end
|
||||
|
@ -15,6 +15,10 @@ module Homebrew
|
||||
EOS
|
||||
flag "--bintray-org=",
|
||||
description: "Upload to the specified Bintray organisation (default: homebrew)."
|
||||
flag "--bintray-repo=",
|
||||
description: "Upload to the specified Bintray repository (default: mirror)."
|
||||
switch "--no-publish",
|
||||
description: "Upload to Bintray, but don't publish."
|
||||
switch :verbose
|
||||
switch :debug
|
||||
hide_from_man_page!
|
||||
@ -26,11 +30,12 @@ module Homebrew
|
||||
mirror_args.parse
|
||||
|
||||
bintray_org = args.bintray_org || "homebrew"
|
||||
bintray_repo = args.bintray_repo || "mirror"
|
||||
|
||||
bintray = Bintray.new(org: bintray_org)
|
||||
|
||||
args.formulae.each do |formula|
|
||||
mirror_url = bintray.mirror_formula(formula)
|
||||
mirror_url = bintray.mirror_formula(formula, repo: bintray_repo, publish_package: !args.no_publish?)
|
||||
ohai "Mirrored #{formula.full_name} to #{mirror_url}!"
|
||||
end
|
||||
end
|
||||
|
@ -41,6 +41,11 @@ module Homebrew
|
||||
description: "Upload to the specified Bintray organisation (default: homebrew)."
|
||||
flag "--tap=",
|
||||
description: "Target tap repository (default: homebrew/core)."
|
||||
flag "--root-url=",
|
||||
description: "Use the specified <URL> as the root of the bottle's URL instead of Homebrew's default."
|
||||
flag "--bintray-mirror=",
|
||||
description: "Use the specified Bintray repository to automatically mirror stable URLs "\
|
||||
"defined in the formulae (default: mirror)"
|
||||
switch :verbose
|
||||
switch :debug
|
||||
min_named 1
|
||||
@ -128,6 +133,30 @@ module Homebrew
|
||||
def formulae_need_bottles?(tap, original_commit)
|
||||
return if Homebrew.args.dry_run?
|
||||
|
||||
changed_formulae(tap, original_commit).any? do |f|
|
||||
!f.bottle_unneeded? && !f.bottle_disabled?
|
||||
end
|
||||
end
|
||||
|
||||
def mirror_formulae(tap, original_commit, publish: true, org:, repo:)
|
||||
changed_formulae(tap, original_commit).select do |f|
|
||||
stable_urls = [f.stable.url] + f.stable.mirrors
|
||||
stable_urls.grep(%r{^https://dl.bintray.com/#{org}/#{repo}/}) do |mirror_url|
|
||||
if Homebrew.args.dry_run?
|
||||
puts "brew mirror #{f.full_name}"
|
||||
else
|
||||
odebug "Mirroring #{mirror_url}"
|
||||
mirror_args = ["mirror", f.full_name]
|
||||
mirror_args << "--bintray-org=#{org}" if org
|
||||
mirror_args << "--bintray-repo=#{repo}" if repo
|
||||
mirror_args << "--no-publish" unless publish
|
||||
system HOMEBREW_BREW_FILE, *mirror_args
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def changed_formulae(tap, original_commit)
|
||||
if Homebrew::EnvConfig.disable_load_formula?
|
||||
opoo "Can't check if updated bottles are necessary as formula loading is disabled!"
|
||||
return
|
||||
@ -136,19 +165,17 @@ module Homebrew
|
||||
Utils.popen_read("git", "-C", tap.path, "diff-tree",
|
||||
"-r", "--name-only", "--diff-filter=AM",
|
||||
original_commit, "HEAD", "--", tap.formula_dir)
|
||||
.lines.each do |line|
|
||||
.lines.map do |line|
|
||||
next unless line.end_with? ".rb\n"
|
||||
|
||||
name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}"
|
||||
begin
|
||||
f = Formula[name]
|
||||
Formula[name]
|
||||
rescue Exception # rubocop:disable Lint/RescueException
|
||||
# Make sure we catch syntax errors.
|
||||
next
|
||||
end
|
||||
return true if !f.bottle_unneeded? && !f.bottle_disabled?
|
||||
end
|
||||
nil
|
||||
end.compact
|
||||
end
|
||||
|
||||
def download_artifact(url, dir, pr)
|
||||
@ -181,12 +208,11 @@ module Homebrew
|
||||
|
||||
if bintray_user.blank? || bintray_key.blank?
|
||||
odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !args.dry_run? && !args.no_upload?
|
||||
else
|
||||
bintray = Bintray.new(user: bintray_user, key: bintray_key, org: bintray_org)
|
||||
end
|
||||
|
||||
workflow = args.workflow || "tests.yml"
|
||||
artifact = args.artifact || "bottles"
|
||||
mirror_repo = args.bintray_mirror || "mirror"
|
||||
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
||||
|
||||
setup_git_environment!
|
||||
@ -206,6 +232,10 @@ module Homebrew
|
||||
cherry_pick_pr! pr, path: tap.path
|
||||
signoff! pr, path: tap.path unless args.clean?
|
||||
|
||||
unless args.no_upload?
|
||||
mirror_formulae(tap, original_commit, org: bintray_org, repo: mirror_repo, publish: !args.no_publish?)
|
||||
end
|
||||
|
||||
unless formulae_need_bottles? tap, original_commit
|
||||
ohai "Skipping artifacts for ##{pr} as the formulae don't need bottles"
|
||||
next
|
||||
@ -214,41 +244,14 @@ module Homebrew
|
||||
url = GitHub.get_artifact_url(user, repo, pr, workflow_id: workflow, artifact_name: artifact)
|
||||
download_artifact(url, dir, pr)
|
||||
|
||||
json_files = Dir["*.json"]
|
||||
|
||||
if Homebrew.args.dry_run?
|
||||
puts "brew bottle --merge --write #{json_files.join " "}"
|
||||
else
|
||||
quiet_system "#{HOMEBREW_PREFIX}/bin/brew", "bottle", "--merge", "--write", *json_files
|
||||
end
|
||||
|
||||
next if args.no_upload?
|
||||
|
||||
if Homebrew.args.dry_run?
|
||||
puts "Upload bottles described by these JSON files to Bintray:\n #{json_files.join("\n ")}"
|
||||
else
|
||||
bintray.upload_bottle_json json_files, publish_package: !args.no_publish?
|
||||
end
|
||||
|
||||
bottles_hash = json_files.reduce({}) do |hash, json_file|
|
||||
hash.deep_merge(JSON.parse(IO.read(json_file)))
|
||||
end
|
||||
|
||||
bottles_hash.each do |formula_name, _|
|
||||
formula = Formula[formula_name]
|
||||
stable_urls = [formula.stable.url] + formula.stable.mirrors
|
||||
stable_urls.grep(%r{^https://dl.bintray.com/homebrew/mirror/}) do |mirror_url|
|
||||
if Homebrew.args.dry_run?
|
||||
puts "Mirror formulae sources described by these JSON files to Bintray:\n #{json_files.join("\n ")}"
|
||||
next
|
||||
end
|
||||
|
||||
next if bintray.stable_mirrored?(mirror_url)
|
||||
|
||||
mirror_url = bintray.mirror_formula(formula)
|
||||
ohai "Mirrored #{formula.full_name} to #{mirror_url}!"
|
||||
end
|
||||
end
|
||||
upload_args = ["pr-upload"]
|
||||
upload_args << "--no-publish" if args.no_publish?
|
||||
upload_args << "--dry-run" if args.dry_run?
|
||||
upload_args << "--root_url=#{args.root_url}" if args.root_url
|
||||
upload_args << "--bintray-org=#{bintray_org}"
|
||||
system HOMEBREW_BREW_FILE, *upload_args
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user