Skip to content

Commit

Permalink
(SIMP-3954) Switch to Gem::Version for comparisons (#99)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trevor-vaughan authored Nov 28, 2017
1 parent deac905 commit 52d213b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/simp/rake/helpers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module Simp; end
module Simp::Rake; end

class Simp::Rake::Helpers
VERSION = '5.1.3'
VERSION = '5.1.4'
end
11 changes: 6 additions & 5 deletions lib/simp/rake/pupmod/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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")
Expand All @@ -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}"
Expand Down
6 changes: 2 additions & 4 deletions lib/simp/rpm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'securerandom'
require 'puppet/util'

module Simp
# An Simp::RPM instance represents RPM metadata extracted from an
Expand Down Expand Up @@ -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}'")
Expand Down

0 comments on commit 52d213b

Please sign in to comment.