Skip to content

Commit 052a0d4

Browse files
committed
(BOLT-1360) Include a script for checking for gem updates
This commit adds a simplified version of the script https://github.com/puppetlabs/bolt-vanagon/blob/master/generate.rb used to generate a list of gems that could be updated. Instead of modifying component files directly it attempts to parse the version and compares it to the version specified in the gemfile passes as positional argument. The script will alert when a gem from Gemfile.lock should be updated and when it is not mirrored in artifactory.
1 parent ec08d22 commit 052a0d4

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

generate.rb

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'bundler'
4+
require 'net/http'
5+
6+
lockfile = ARGV.first
7+
if lockfile.nil?
8+
warn 'Usage: generate.rb /path/to/Gemfile.lock'
9+
exit 1
10+
end
11+
12+
unless File.exist? lockfile
13+
warn "Lockfile #{lockfile} does not exist"
14+
exit 1
15+
end
16+
17+
unless File.readable? lockfile
18+
warn "Lockfile #{lockfile} could not be read"
19+
exit 1
20+
end
21+
22+
# Parse the Gemfile.lock and build a map or gem name to version
23+
bundle = Bundler::LockfileParser.new(Bundler.read_file(lockfile))
24+
gem_name_to_version = bundle.specs.each_with_object({}) { |gem_object, acc| acc[gem_object.name] = gem_object.version }
25+
26+
# Print a warning if the version defined in the component defintion is
27+
# Older than the version in the Gemfile.lock
28+
def check_update(component_def, spec, gem_name_to_version)
29+
component_def.each_line do |line|
30+
# TODO: Some of the component files handle multiple versions with a case statement (for example net-ssh).
31+
# Add more logic to compare each of those versions. For now there are only a hand full.
32+
if line =~ /pkg.version/
33+
ver = Gem::Version.new(line.scan(/\d\.*/).join(''))
34+
if gem_name_to_version[spec.name] > ver
35+
warn "Update needed for: #{spec.name} \nUpgrade from #{ver} to #{gem_name_to_version[spec.name]}\n\n"
36+
end
37+
end
38+
end
39+
end
40+
41+
http = Net::HTTP.start('artifactory.delivery.puppetlabs.net', use_ssl: true)
42+
43+
bundle.specs.each do |s|
44+
filename = "configs/components/rubygem-#{s.name}.rb"
45+
next unless File.exist?(filename)
46+
# Check if an update is needed by comparing version in component defintion to version in lockfile
47+
check_update(File.read(filename), s, gem_name_to_version)
48+
# Warn if the gem is not mirrored in artifactory
49+
resp = http.head("/artifactory/generic__buildsources/buildsources/#{s.name}-#{s.version}.gem")
50+
unless resp.is_a?(Net::HTTPSuccess)
51+
warn "Update Needed for #{s.name}:\n!mirrorsource https://rubygems.org/downloads/#{s.name}-#{s.version}.gem\n\n"
52+
end
53+
end

0 commit comments

Comments
 (0)