Module: Pkg::Gem

Defined in:
lib/packaging/gem.rb

Class Method Summary collapse

Class Method Details

.rsync_to_downloads(file) ⇒ Object

Use rsync to deploy a file and any associated detached signatures, checksums, or other glob-able artifacts to an external download server.



11
12
13
14
15
# File 'lib/packaging/gem.rb', line 11

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(file) ⇒ Object



4
5
6
7
# File 'lib/packaging/gem.rb', line 4

def ship(file)
  rsync_to_downloads(file)
  ship_to_rubygems(file)
end

.ship_to_internal_mirror(file) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/packaging/gem.rb', line 62

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

.ship_to_rubygems(file, options = {}) ⇒ Object

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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/packaging/gem.rb', line 34

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
  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)
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

.shipped_to_rubygems?(gem_name, gem_version, gem_platform) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/packaging/gem.rb', line 17

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
  end
  return !gem.empty?
rescue => e
  puts "Something went wrong searching for gem '#{gem_name}':"
  puts e
  puts "Perhaps you're shipping '#{gem_name}' for the first time?"
  return false
end