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")
|
status_code.start_with?("2")
|
||||||
end
|
end
|
||||||
|
|
||||||
def mirror_formula(formula, repo: "mirror")
|
def mirror_formula(formula, repo: "mirror", publish_package: false)
|
||||||
package = Utils::Bottles::Bintray.package formula.name
|
package = Utils::Bottles::Bintray.package formula.name
|
||||||
|
|
||||||
create_package(repo: repo, package: package) unless package_exists?(repo: repo, package: package)
|
create_package(repo: repo, package: package) unless package_exists?(repo: repo, package: package)
|
||||||
@ -93,7 +93,10 @@ class Bintray
|
|||||||
sha256: formula.stable.checksum,
|
sha256: formula.stable.checksum,
|
||||||
remote_file: filename,
|
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
|
destination_url
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,10 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
flag "--bintray-org=",
|
flag "--bintray-org=",
|
||||||
description: "Upload to the specified Bintray organisation (default: homebrew)."
|
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 :verbose
|
||||||
switch :debug
|
switch :debug
|
||||||
hide_from_man_page!
|
hide_from_man_page!
|
||||||
@ -26,11 +30,12 @@ module Homebrew
|
|||||||
mirror_args.parse
|
mirror_args.parse
|
||||||
|
|
||||||
bintray_org = args.bintray_org || "homebrew"
|
bintray_org = args.bintray_org || "homebrew"
|
||||||
|
bintray_repo = args.bintray_repo || "mirror"
|
||||||
|
|
||||||
bintray = Bintray.new(org: bintray_org)
|
bintray = Bintray.new(org: bintray_org)
|
||||||
|
|
||||||
args.formulae.each do |formula|
|
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}!"
|
ohai "Mirrored #{formula.full_name} to #{mirror_url}!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -41,6 +41,11 @@ module Homebrew
|
|||||||
description: "Upload to the specified Bintray organisation (default: homebrew)."
|
description: "Upload to the specified Bintray organisation (default: homebrew)."
|
||||||
flag "--tap=",
|
flag "--tap=",
|
||||||
description: "Target tap repository (default: homebrew/core)."
|
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 :verbose
|
||||||
switch :debug
|
switch :debug
|
||||||
min_named 1
|
min_named 1
|
||||||
@ -128,6 +133,30 @@ module Homebrew
|
|||||||
def formulae_need_bottles?(tap, original_commit)
|
def formulae_need_bottles?(tap, original_commit)
|
||||||
return if Homebrew.args.dry_run?
|
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?
|
if Homebrew::EnvConfig.disable_load_formula?
|
||||||
opoo "Can't check if updated bottles are necessary as formula loading is disabled!"
|
opoo "Can't check if updated bottles are necessary as formula loading is disabled!"
|
||||||
return
|
return
|
||||||
@ -136,19 +165,17 @@ module Homebrew
|
|||||||
Utils.popen_read("git", "-C", tap.path, "diff-tree",
|
Utils.popen_read("git", "-C", tap.path, "diff-tree",
|
||||||
"-r", "--name-only", "--diff-filter=AM",
|
"-r", "--name-only", "--diff-filter=AM",
|
||||||
original_commit, "HEAD", "--", tap.formula_dir)
|
original_commit, "HEAD", "--", tap.formula_dir)
|
||||||
.lines.each do |line|
|
.lines.map do |line|
|
||||||
next unless line.end_with? ".rb\n"
|
next unless line.end_with? ".rb\n"
|
||||||
|
|
||||||
name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}"
|
name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}"
|
||||||
begin
|
begin
|
||||||
f = Formula[name]
|
Formula[name]
|
||||||
rescue Exception # rubocop:disable Lint/RescueException
|
rescue Exception # rubocop:disable Lint/RescueException
|
||||||
# Make sure we catch syntax errors.
|
# Make sure we catch syntax errors.
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
return true if !f.bottle_unneeded? && !f.bottle_disabled?
|
end.compact
|
||||||
end
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_artifact(url, dir, pr)
|
def download_artifact(url, dir, pr)
|
||||||
@ -181,12 +208,11 @@ module Homebrew
|
|||||||
|
|
||||||
if bintray_user.blank? || bintray_key.blank?
|
if bintray_user.blank? || bintray_key.blank?
|
||||||
odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !args.dry_run? && !args.no_upload?
|
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
|
end
|
||||||
|
|
||||||
workflow = args.workflow || "tests.yml"
|
workflow = args.workflow || "tests.yml"
|
||||||
artifact = args.artifact || "bottles"
|
artifact = args.artifact || "bottles"
|
||||||
|
mirror_repo = args.bintray_mirror || "mirror"
|
||||||
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
tap = Tap.fetch(args.tap || CoreTap.instance.name)
|
||||||
|
|
||||||
setup_git_environment!
|
setup_git_environment!
|
||||||
@ -206,6 +232,10 @@ module Homebrew
|
|||||||
cherry_pick_pr! pr, path: tap.path
|
cherry_pick_pr! pr, path: tap.path
|
||||||
signoff! pr, path: tap.path unless args.clean?
|
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
|
unless formulae_need_bottles? tap, original_commit
|
||||||
ohai "Skipping artifacts for ##{pr} as the formulae don't need bottles"
|
ohai "Skipping artifacts for ##{pr} as the formulae don't need bottles"
|
||||||
next
|
next
|
||||||
@ -214,41 +244,14 @@ module Homebrew
|
|||||||
url = GitHub.get_artifact_url(user, repo, pr, workflow_id: workflow, artifact_name: artifact)
|
url = GitHub.get_artifact_url(user, repo, pr, workflow_id: workflow, artifact_name: artifact)
|
||||||
download_artifact(url, dir, pr)
|
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?
|
next if args.no_upload?
|
||||||
|
|
||||||
if Homebrew.args.dry_run?
|
upload_args = ["pr-upload"]
|
||||||
puts "Upload bottles described by these JSON files to Bintray:\n #{json_files.join("\n ")}"
|
upload_args << "--no-publish" if args.no_publish?
|
||||||
else
|
upload_args << "--dry-run" if args.dry_run?
|
||||||
bintray.upload_bottle_json json_files, publish_package: !args.no_publish?
|
upload_args << "--root_url=#{args.root_url}" if args.root_url
|
||||||
end
|
upload_args << "--bintray-org=#{bintray_org}"
|
||||||
|
system HOMEBREW_BREW_FILE, *upload_args
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user