module Rake::Gitversion
Constants
- VERSION
- VERSION_FILE_PATH
Path to
VERSION
file
Public Class Methods
install_rake_tasks()
click to toggle source
Create Rake
task 'set_version' which writes generated version string to VERSION
file.
# File lib/rake/gitversion.rb, line 32 def self.install_rake_tasks desc('Get version from git and save to VERSION file') task(:set_version) do version = version_from_git path = VERSION_FILE_PATH begin File.open(path, 'w') do |file| file.write(version) end rescue StandardError => error pp error raise("File #{path} unwritable.") end end end
version_from_git(git_desc = nil)
click to toggle source
Get version from git via 'git describe'. Requires annotated git tags in format 'v<MAJOR>.<MINOR>' like 'v4.11' @param git_desc [String] output from 'git describe –long –dirty=-dirty'
# File lib/rake/gitversion.rb, line 16 def self.version_from_git(git_desc = nil) if git_desc.nil? git_desc = `git describe --long --dirty=-dirty` if git_desc.empty? raise("ERROR: git describe failed. Make sure you are in git and" + " there are annotated version tags like v0.1.") end end match = git_desc.match(/v(\d+)\.(\d+)-(\d+)-\w+(-dirty)?/) raise "'#{git_desc}' has invalid format" unless match patchlevel = match[4] ? "#{match[3].to_i + 1}.dev" : match[3] "#{match[1]}.#{match[2]}.#{patchlevel}" end