From 52d213b89972d67757dfdad7966f9482be6296ce Mon Sep 17 00:00:00 2001 From: Trevor Vaughan Date: Tue, 28 Nov 2017 08:51:07 -0500 Subject: [PATCH] (SIMP-3954) Switch to Gem::Version for comparisons (#99) Switched back to Gem::Version from the inbuilt Puppet version comparator since Gem::Version matches the semantics for RPM versioning. SIMP-3954 #comment Switch back to Gem::Version --- CHANGELOG.md | 4 ++++ lib/simp/rake/helpers/version.rb | 2 +- lib/simp/rake/pupmod/helpers.rb | 11 ++++++----- lib/simp/rpm.rb | 6 ++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b7c2591..a5f8bb07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 5.1.4 / 2017-11-27 +* Switch back to using Gem::Version.new instead of Puppet's vercmp since + Gem::Version matches the standard RPM version semantics and Puppet does not. + ### 5.1.3 / 2017-10-16 * Ensure that the first package run uses the existing Bundle environment and falls back to a clean Bundle environment on failure. diff --git a/lib/simp/rake/helpers/version.rb b/lib/simp/rake/helpers/version.rb index ce533f9e..463edcc5 100644 --- a/lib/simp/rake/helpers/version.rb +++ b/lib/simp/rake/helpers/version.rb @@ -2,5 +2,5 @@ module Simp; end module Simp::Rake; end class Simp::Rake::Helpers - VERSION = '5.1.3' + VERSION = '5.1.4' end diff --git a/lib/simp/rake/pupmod/helpers.rb b/lib/simp/rake/pupmod/helpers.rb index 404e609c..4a69bd87 100644 --- a/lib/simp/rake/pupmod/helpers.rb +++ b/lib/simp/rake/pupmod/helpers.rb @@ -201,7 +201,6 @@ def changelog_annotation( quiet = false, file = nil ) EOM task :compare_latest_tag, [:tags_source, :ignore_owner, :verbose] do |t,args| require 'json' - require 'puppet/util/package' tags_source = args[:tags_source].nil? ? 'origin' : args[:tags_source] ignore_owner = true if args[:ignore_owner].to_s == 'true' @@ -220,7 +219,7 @@ def changelog_annotation( quiet = false, file = nil ) if tags.empty? puts "No tags exist from #{tags_source}" else - last_tag = (tags.sort { |a,b| Puppet::Util::Package::versioncmp(a,b) })[-1] + last_tag = (tags.sort { |a,b| Gem::Version.new(a) <=> Gem::Version.new(b) })[-1] # determine mission-impacting files that have changed files_changed = `git diff tags/#{last_tag} --name-only`.strip.split("\n") @@ -246,10 +245,12 @@ def changelog_annotation( quiet = false, file = nil ) end end - cmp_result = Puppet::Util::Package::versioncmp(module_version, last_tag) - if cmp_result < 0 + curr_module_version = Gem::Version.new(module_version) + last_tag_version = Gem::Version.new(last_tag) + + if curr_module_version < last_tag_version fail("ERROR: Version regression. '#{module_version}' < last tag '#{last_tag}'") - elsif cmp_result == 0 + elsif curr_module_version == last_tag_version fail("ERROR: Version update beyond last tag '#{last_tag}' is required for changes to #{files_changed}") else puts " New tag of version '#{module_version}' is required for changes to #{files_changed}" diff --git a/lib/simp/rpm.rb b/lib/simp/rpm.rb index 221beaf5..0a1c9433 100644 --- a/lib/simp/rpm.rb +++ b/lib/simp/rpm.rb @@ -1,5 +1,4 @@ require 'securerandom' -require 'puppet/util' module Simp # An Simp::RPM instance represents RPM metadata extracted from an @@ -226,9 +225,8 @@ def package_newer?(package, other_rpm) end begin - # Puppet::Util::Package::versioncmp can handle simp-doc-UNKNOWN-0.el7, whereas - # Gem::Version can't - return Puppet::Util::Package::versioncmp(full_version(package), other_full_version) > 0 + + return Gem::Version.new(full_version(package)) > Gem::Version.new(other_full_version) rescue ArgumentError, NoMethodError fail("Could not compare RPMs '#{rpm_name(package)}' and '#{other_rpm}'")