Last active
January 29, 2017 05:34
-
-
Save itsprdp/1e005177d2403f28c660 to your computer and use it in GitHub Desktop.
Git tag version bumper
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
module Release | |
@tags = %x[ git tag --sort version:refname ].split("\n") | |
@current_tag = @tags.last | |
@current_version = @current_tag.gsub("v","") | |
@major, @minor, @patch = @current_version.split(".").map(&:to_i) | |
def self.tags | |
@tags | |
end | |
def self.current_tag | |
@current_tag | |
end | |
def self.bump_version release_type, metadata | |
case release_type | |
when "major" | |
@major += 1 | |
@minor = @patch = 0 | |
when "minor" | |
@minor += 1 | |
@patch = 0 | |
when "patch" | |
@patch += 1 | |
else # Default case | |
@patch += 1 | |
end | |
bumped_version = "v#{@major}.#{@minor}.#{@patch}" | |
(metadata.present?)? bumped_version + "-#{metadata}" : bumped_version | |
end | |
def self.next_tag release_type="patch",metadata=nil | |
self.bump_version(release_type,metadata) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment