Skip to content

Commit

Permalink
Fix bugs in rake rev
Browse files Browse the repository at this point in the history
Thanks to tnir for the code, from the nronn fork at:
  * n-ronn/nronn@a67c73d
  * n-ronn/nronn@653ad57

Co-authored-by: Takuya Noguchi <[email protected]>
  • Loading branch information
apjanke and tnir committed Jan 6, 2023
1 parent d3be2ab commit 87612a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end
task :rev do
rev = ENV['REV'] || `git describe --tags`.chomp
data = File.read('lib/ronn.rb')
data.gsub!(/^( *)REV *=.*/, "\\1REV = '#{rev}'")
data.gsub!(/^( *)REV *=.*/, "\\1REV = '#{rev.sub(/\Av/, '')}'.freeze")
File.open('lib/ronn.rb', 'wb') { |fd| fd.write(data) }
puts "revision: #{rev}"
puts "version: #{`ruby -Ilib -rronn -e 'puts Ronn::VERSION'`}"
Expand Down
8 changes: 3 additions & 5 deletions lib/ronn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def self.release?

# A semantic version number based on the git revision. The third element
# of the version is incremented by the commit offset, such that version
# 0.6.6-5-gdacd74b => 0.6.11
# v0.6.6-5-gdacd74b => 0.6.11
def self.version
ver = revision[/^[0-9.-]+/].split(/[.-]/).map(&:to_i)
ver = revision.sub(/\Av/, '')[/^[0-9.-]+/].split(/[.-]/).map(&:to_i)
ver[2] += ver.pop while ver.size > 3
ver.join('.')
end

# The string revision as reported by: git-describe --tags. This is just the
# tag name when a tag references the HEAD commit (e.g. 0.6.25). When the HEAD
# tag name when a tag references the HEAD commit (e.g. v0.6.25). When the HEAD
# commit is not tagged, this is a "<tag>-<offset>-<sha1>" string:
# <tag> - closest tag name
# <offset> - number of commits ahead of <tag>
Expand All @@ -40,8 +40,6 @@ def self.revision
end

# value generated by: rake rev
# or edit manually; I'm not sure of how rake rev interacts with git
# tags -apjanke
REV = '0.10.1.pre1'.freeze
VERSION = version
end

0 comments on commit 87612a8

Please sign in to comment.