lib/packaging/gem.rb in packaging-0.99.22 vs lib/packaging/gem.rb in packaging-0.99.23
- old
+ new
@@ -1,5 +1,6 @@
+require 'json'
module Pkg::Gem
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.
@@ -13,13 +14,28 @@
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
+ def shipped_to_rubygems?(gem_name, gem_version)
+ gem_data = JSON.parse(`curl https://rubygems.org/api/v1/versions/#{gem_name}.json`)
+ gem_versions = gem_data.map { |version| version['number'] }
+ return gem_versions.include? gem_version
+ rescue => e
+ puts "Uh oh, something went wrong searching for gem '#{gem_name}':"
+ puts e
+ puts "Perhaps you're shipping gem '#{gem_name}' for the first time? Congrats!"
+ return false
+ 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 = {})
+ if shipped_to_rubygems?(Pkg::Config.gem_name, Pkg::Config.gemversion)
+ puts "#{file} has already been shipped to rubygems, skipping . . ."
+ return
+ end
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)