Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Last active August 19, 2016 21:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikecmpbll/a60dd5bd36e057e6d130 to your computer and use it in GitHub Desktop.
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.
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