Skip to content

Commit

Permalink
Fix compare_semver() to be ruby-2.5 compatible, and handle differen…
Browse files Browse the repository at this point in the history
…t length versions symmetrically.
  • Loading branch information
maargenton committed Jul 31, 2023
1 parent cfea997 commit 7c7fefd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,22 +525,26 @@ def format_summary_table(summary)

def compare_semver(a, b)
def parse(v)
vv = (v[1..] if v[0] == 'v' || v).split('-', 2)
vv = (v[1..-1] if v[0] == 'v' || v).split('-', 2)
return ((vv[0].split('.').map{|v| v.to_i}) + [0]*3)[0...3] +
((vv[1] || "+").split('+', 2))[0].split('.').map {|v| Integer(v, exception: false) || v}
end
def cmp(a,b)
a <=> b || (a.nil? ? -1 : b.nil? ? 1 : a.is_a?(Numeric) ? -1 : 1)
end
def zip_ex(a, b)
a.length >= b.length ? a.zip(b) : b.zip(a).map(&:reverse)
end

a, b = parse(a), parse(b)
c = a[0...3] <=> b[0...3]
return c if c != 0
return b.length <=> a.length if a.length == 3 || b.length == 3
a[3...].zip(b[3...]).each { |aa,bb| c = cmp(aa,bb); return c if c != 0 }
zip_ex(a[3..-1], b[3..-1]).each { |aa,bb| c = cmp(aa,bb); return c if c != 0 }
return 0
end


# compare_semver("v0.4.1-rc.8.g6f6731e.3.4", "v0.4.1-rc.8.g6f6731e.3.4")

def check_release_build()
Expand Down

0 comments on commit 7c7fefd

Please sign in to comment.