dev-cmd/mirror: switch to Bintray wrapper
This commit is contained in:
		
							parent
							
								
									a34e0c1893
								
							
						
					
					
						commit
						cc799b1f31
					
				@ -1,5 +1,6 @@
 | 
				
			|||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require "bintray"
 | 
				
			||||||
require "cli/parser"
 | 
					require "cli/parser"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
@ -12,6 +13,8 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        Reupload the stable URL of a formula to Bintray for use as a mirror.
 | 
					        Reupload the stable URL of a formula to Bintray for use as a mirror.
 | 
				
			||||||
      EOS
 | 
					      EOS
 | 
				
			||||||
 | 
					      flag "--bintray-org=",
 | 
				
			||||||
 | 
					           description: "Upload to the specified Bintray organisation (default: homebrew)."
 | 
				
			||||||
      switch :verbose
 | 
					      switch :verbose
 | 
				
			||||||
      switch :debug
 | 
					      switch :debug
 | 
				
			||||||
      hide_from_man_page!
 | 
					      hide_from_man_page!
 | 
				
			||||||
@ -22,25 +25,16 @@ module Homebrew
 | 
				
			|||||||
  def mirror
 | 
					  def mirror
 | 
				
			||||||
    mirror_args.parse
 | 
					    mirror_args.parse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bintray_user = Homebrew::EnvConfig.bintray_user
 | 
					    bintray_org = args.bintray_org || "homebrew"
 | 
				
			||||||
    bintray_key = Homebrew::EnvConfig.bintray_key
 | 
					    bintray_repo = "mirror"
 | 
				
			||||||
    raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key
 | 
					
 | 
				
			||||||
 | 
					    bintray = Bintray.new(org: bintray_org)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args.formulae.each do |f|
 | 
					    args.formulae.each do |f|
 | 
				
			||||||
      bintray_package = Utils::Bottles::Bintray.package f.name
 | 
					      bintray_package = Utils::Bottles::Bintray.package f.name
 | 
				
			||||||
      bintray_repo_url = "https://api.bintray.com/packages/homebrew/mirror"
 | 
					 | 
				
			||||||
      package_url = "#{bintray_repo_url}/#{bintray_package}"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      unless system curl_executable, "--silent", "--fail", "--output", "/dev/null", package_url
 | 
					      unless bintray.package_exists?(repo: bintray_repo, package: bintray_package)
 | 
				
			||||||
        package_blob = <<~JSON
 | 
					        bintray.create_package repo: bintray_repo, package: bintray_package
 | 
				
			||||||
          {"name": "#{bintray_package}",
 | 
					 | 
				
			||||||
           "public_download_numbers": true,
 | 
					 | 
				
			||||||
           "public_stats": true}
 | 
					 | 
				
			||||||
        JSON
 | 
					 | 
				
			||||||
        curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}",
 | 
					 | 
				
			||||||
             "--header", "Content-Type: application/json",
 | 
					 | 
				
			||||||
             "--data", package_blob, bintray_repo_url
 | 
					 | 
				
			||||||
        puts
 | 
					 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      downloader = f.downloader
 | 
					      downloader = f.downloader
 | 
				
			||||||
@ -49,14 +43,18 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      filename = downloader.basename
 | 
					      filename = downloader.basename
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      destination_url = "https://dl.bintray.com/homebrew/mirror/#{filename}"
 | 
					      destination_url = "https://dl.bintray.com/#{bintray_org}/#{bintray_repo}/#{filename}"
 | 
				
			||||||
      ohai "Uploading to #{destination_url}"
 | 
					      ohai "Uploading to #{destination_url}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      content_url =
 | 
					      bintray.upload(
 | 
				
			||||||
        "https://api.bintray.com/content/homebrew/mirror/#{bintray_package}/#{f.pkg_version}/#{filename}?publish=1"
 | 
					        downloader.cached_location,
 | 
				
			||||||
      curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}",
 | 
					        repo:        bintray_repo,
 | 
				
			||||||
           "--upload-file", downloader.cached_location, content_url
 | 
					        package:     bintray_package,
 | 
				
			||||||
      puts
 | 
					        version:     f.pkg_version,
 | 
				
			||||||
 | 
					        sha256:      f.stable.checksum,
 | 
				
			||||||
 | 
					        remote_file: filename,
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      bintray.publish(repo: bintray_repo, package: bintray_package, version: f.pkg_version)
 | 
				
			||||||
      ohai "Mirrored #{filename}!"
 | 
					      ohai "Mirrored #{filename}!"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user