Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PE-27792) Fix version_is_less for current versioning scheme #1630

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions lib/beaker/shared/semvar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ module Semvar
#@param [String] b A version of the form '\d.\d.\d.*'
#@return [Boolean] true if a is less than b, otherwise return false
#
#@note 3.0.0-160-gac44cfb is greater than 3.0.0, and 2.8.2
#@note -rc being less than final builds is not yet implemented.
#@note This has been updated for our current versioning scheme.
#@note 2019.5.0 is greater than 2019.5.0-rc0
#@note 2019.5.0-rc0-1-gabc1234 is greater than 2019.5.0-rc0
#@note 2019.5.0-rc1 is greater than 2019.5.0-rc0-1-gabc1234
#@note 2019.5.0-1-gabc1234 is greater than 2019.5.0
def version_is_less a, b
a_nums = a.split('-')[0].split('.')
b_nums = b.split('-')[0].split('.')
Expand All @@ -24,16 +27,45 @@ def version_is_less a, b
end
end
#checks all dots, they are equal so examine the rest
a_rest = a.split('-', 2)[1]
b_rest = b.split('-', 2)[1]
if a_rest and b_rest and a_rest < b_rest
return false
elsif a_rest and not b_rest
a_rest = a.split('-').drop(1)
a_is_release = a_rest.empty?
a_is_rc = !a_is_release && !!(a_rest[0] =~ /rc\d+/)
b_rest = b.split('-').drop(1)
b_is_release = b_rest.empty?
b_is_rc = !b_is_release && !!(b_rest[0] =~ /rc\d+/)

if a_is_release && b_is_release
# They are equal
return false
elsif not a_rest and b_rest
return true
elsif !a_is_release && !b_is_release
a_next = a_rest.shift
b_next = b_rest.shift
if a_is_rc && b_is_rc
a_rc = a_next.gsub('rc','').to_i
b_rc = b_next.gsub('rc','').to_i
if a_rc < b_rc
return true
elsif a_rc > b_rc
return false
else
a_next = a_rest.shift
b_next = b_rest.shift
if a_next && b_next
return a_next.to_i < b_next.to_i
else
# If a has nothing after -rc#, it is a tagged RC and
# b must be a later build after this tag.
return a_next.nil?
end
end
else
# If one of them is not an rc (and also not a release),
# that one is a post-release build. So if a is the RC, it is less.
return a_is_rc
end
else
return (b_is_release && a_is_rc) || (a_is_release && !b_is_rc)
end
return false
end

# Gets the max semver version from a list of them
Expand Down
24 changes: 22 additions & 2 deletions spec/beaker/shared/semvar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@ module Shared
expect( subject.version_is_less( '2015.3.0-rc0-8-gf80879a', '2016' ) ).to be === true
end

it 'reports 2015.3.0-rc0-8-gf80879a is not less than 2015.3.0' do
expect( subject.version_is_less( '2015.3.0-rc0-8-gf80879a', '2015.3.0' ) ).to be === false
it 'reports 2015.3.0-rc0-8-gf80879a is less than 2015.3.0' do
expect( subject.version_is_less( '2015.3.0-rc0-8-gf80879a', '2015.3.0' ) ).to be === true
end

it 'reports that 2015.3.0-rc0 is less than 2015.3.0-rc0-8-gf80879a' do
expect( subject.version_is_less( '2015.3.0-rc0', '2015.3.0-rc0-8-gf80879a' ) ).to be === true
end

it 'reports that 2015.3.0-rc2 is less than 2015.3.0-rc10 (not using string comparison)' do
expect( subject.version_is_less( '2015.3.0-rc2', '2015.3.0-rc10' ) ).to be === true
end

it 'reports that 2015.3.0 is less than 2015.3.0-1-gabc1234' do
expect( subject.version_is_less( '2015.3.0', '2015.3.0-1-gabc1234' ) ).to be === true
end

it 'reports that 2015.3.0-rc2 is less than 2015.3.0-1-gabc1234' do
expect( subject.version_is_less( '2015.3.0-rc2', '2015.3.0-1-gabc1234' ) ).to be === true
end

it 'reports 2015.3.0-rc0-8-gf80879a is not less than 3.0.0' do
Expand Down Expand Up @@ -41,6 +57,10 @@ module Shared
it 'reports 2.8 is less than 2.9' do
expect( subject.version_is_less( '2.8', '2.9' ) ).to be === true
end

it 'reports that 2015.3.0 is not less than 2015.3.0' do
expect( subject.version_is_less( '2015.3.0', '2015.3.0' ) ).to be == false
end
end

describe 'max_version' do
Expand Down