lib/packaging/gem.rb in packaging-0.88.77 vs lib/packaging/gem.rb in packaging-0.99.0
- old
+ new
@@ -1,70 +1,112 @@
-require 'json'
module Pkg::Gem
+ @nexus_config = "#{ENV['HOME']}/.gem/nexus"
+
class << self
+ # This is preserved because I don't want to update the deprecated code path
+ # yet; I'm not entirely sure I've fixed everything that might attempt
+ # to call this method so this is now a wrapper for a wrapper.
def ship(file)
+ ship_to_stickler(file)
+ ship_to_nexus(file)
rsync_to_downloads(file)
ship_to_rubygems(file)
end
- # Use rsync to deploy a file and any associated detached signatures,
- # checksums, or other glob-able artifacts to an external download server.
- def rsync_to_downloads(file)
- Pkg::Util.deprecate('Pkg::Gem.rsync_to_downloads', 'Pkg::Util::Ship.ship_pkgs')
- Pkg::Util::Ship.ship_pkgs(["#{file}*"], Pkg::Config.gem_host,
- Pkg::Config.gem_path, platform_independent: true)
+ def load_nexus_config
+ if Pkg::Util::File.file_exists?(@nexus_config)
+ config = YAML.load_file(@nexus_config)
+ end
+ config || {}
end
- def shipped_to_rubygems?(gem_name, gem_version, gem_platform)
- rubygems_url = "https://rubygems.org/api/v1/versions/#{gem_name}.json"
- gem_data = JSON.parse(%x(curl --silent #{rubygems_url}))
- gem = gem_data.select do |data|
- data['number'] == gem_version && data['platform'] == gem_platform
+ def write_nexus_config
+ hash = load_nexus_config
+ if hash["GEM_INTERNAL"].nil? || hash["GEM_INTERNAL"][:authorization].nil?
+ puts "Please enter nexus username:"
+ username = Pkg::Util.get_input
+ puts "Please enter nexus password:"
+ password = Pkg::Util.get_input(false)
+ hash["GEM_INTERNAL"] = { :authorization => "Basic #{Pkg::Util.base64_encode("#{username}:#{password}")}" }
end
- return !gem.empty?
+ if hash["GEM_INTERNAL"][:url].nil? || hash["GEM_INTERNAL"][:url] != Pkg::Config.internal_nexus_host
+ hash["GEM_INTERNAL"][:url] = Pkg::Config.internal_nexus_host
+ end
+ File.open(@nexus_config, "w") do |file|
+ file.write(hash.to_yaml)
+ end
+ end
+
+ # Ship a Ruby gem file to a Nexus server, because
+ # you've lost the ability to feel joy anymore.
+ def ship_to_nexus(file)
+ write_nexus_config
+ cmd = "gem nexus #{file} --repo GEM_INTERNAL"
+ if ENV['DRYRUN']
+ puts "[DRY-RUN] #{cmd}"
+ else
+ stdout, _, _ = Pkg::Util::Execution.capture3(cmd, true)
+ # The `gem nexus` command always returns `0` regardless of what the
+ # command results in. In order to properly handle fail cases, this
+ # checks for the success case and fails otherwise. The `ex` command
+ # above will print any output, so the user should have enough info
+ # to debug the failure, and potentially update this fail case if
+ # needed.
+ fail unless stdout.include? "Created"
+ puts "#{file} pushed to nexus server at #{Pkg::Config.internal_nexus_host}"
+ end
rescue => e
- puts "Something went wrong searching for gem '#{gem_name}':"
+ puts "###########################################"
+ puts "# Nexus failed, ensure the nexus gem is installed,"
+ puts "# you have access to #{Pkg::Config.internal_nexus_host}"
+ puts "# and your settings in #{@nexus_config} are correct"
+ puts "###########################################"
+ puts
puts e
- puts "Perhaps you're shipping '#{gem_name}' for the first time?"
- return false
+ raise e
end
+ # Ship a Ruby gem file to a Stickler server, because
+ # you've lost the ability to feel joy anymore.
+ def ship_to_stickler(file)
+ Pkg::Util::Tool.check_tool("stickler")
+ cmd = "stickler push #{file} --server=#{Pkg::Config.internal_stickler_host} 2>/dev/null"
+ if ENV['DRYRUN']
+ puts "[DRY-RUN] #{cmd}"
+ else
+ Pkg::Util::Execution.capture3(cmd)
+ puts "#{file} pushed to stickler server at #{Pkg::Config.internal_stickler_host}"
+ end
+ rescue => e
+ puts "###########################################"
+ puts "# Stickler failed, ensure it's installed"
+ puts "# and you have access to #{Pkg::Config.internal_stickler_host}"
+ puts "###########################################"
+ puts
+ puts e
+ raise e
+ end
+
+ # Use rsync to deploy a file and any associated detached signatures,
+ # checksums, or other glob-able artifacts to an external download server.
+ def rsync_to_downloads(file)
+ Pkg::Util.deprecate('Pkg::Gem.rsync_to_downloads', 'Pkg::Util::Ship.ship_pkgs')
+ Pkg::Util::Ship.ship_pkgs(["#{file}*"], Pkg::Config.gem_host, Pkg::Config.gem_path, platform_independent: true)
+ end
+
# Ship a Ruby gem file to rubygems.org. Requires the existence
# of a ~/.gem/credentials file or else rubygems.org won't have
# any idea who you are.
- def ship_to_rubygems(file, options = {})
- # rubygems uses 'ruby' as the platform when it's not a platform-specific
- # gem
- platform = file.match(/\w+-(?:\d+(?:\.)?)+-(.*)\.gem$/)
- unless platform.nil?
- gem_platform = platform[1]
- end
- gem_platform ||= 'ruby'
-
- if shipped_to_rubygems?(Pkg::Config.gem_name, Pkg::Config.gemversion, gem_platform)
- puts "#{file} has already been shipped to rubygems, skipping."
- return
- end
+ def ship_to_rubygems(file)
Pkg::Util::File.file_exists?("#{ENV['HOME']}/.gem/credentials", :required => true)
- gem_push_command = "gem push #{file}"
- gem_push_command << " --host #{options[:host]}" if options[:host]
- gem_push_command << " --key #{options[:key]}" if options[:key]
- Pkg::Util::Execution.capture3(gem_push_command)
+ Pkg::Util::Execution.capture3("gem push #{file}")
rescue => e
puts "###########################################"
puts "# Publishing to rubygems failed. Make sure your .gem/credentials"
puts "# file is set up and you are an owner of #{Pkg::Config.gem_name}"
puts "###########################################"
puts
puts e
raise e
- end
-
- def ship_to_internal_mirror(file)
- internal_mirror_api_key_name = 'artifactory_api_key'
- ship_to_rubygems(file, {
- host: Pkg::Config.internal_gem_host,
- key: internal_mirror_api_key_name
- })
end
end
end