Last active
August 19, 2016 21:08
-
-
Save mikecmpbll/a60dd5bd36e057e6d130 to your computer and use it in GitHub Desktop.
A wee set of rake tasks to help bump version number using git tags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LEVELS = [:major, :minor, :patch] | |
def version | |
@version ||= begin | |
v = `git describe --always --tags` | |
{}.tap do |h| | |
h[:major], h[:minor], h[:patch], h[:rev], h[:rev_hash] = v[1..-1].split(/[.-]/) | |
end | |
end | |
end | |
def increment(level) | |
v = version.dup | |
v[level] = v[level].to_i + 1 | |
to_zero = LEVELS[LEVELS.index(level)+1..LEVELS.size] | |
to_zero.each{ |z| v[z] = 0 } | |
Rake::Task["version:set"].invoke(v[:major], v[:minor], v[:patch]) | |
end | |
desc "Display version" | |
task :version do | |
puts "Current version: #{`git describe --always --tags`}" | |
end | |
namespace :version do | |
LEVELS.each do |l| | |
desc "Increment #{l} version" | |
task l.to_sym do increment(l.to_sym) end | |
end | |
desc "Set specific major, minor and patch" | |
task :set, [:major, :minor, :patch] do |_, args| | |
sh "git tag v#{args[:major]}.#{args[:minor]}.#{args[:patch]} && git push --tags" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment