Last active
July 12, 2016 15:31
-
-
Save nnarain/4e9e26ae106b75eea8218f0d0d7aae50 to your computer and use it in GitHub Desktop.
git bump script
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
# | |
# Script to bump version number in a git repo | |
# | |
# @author Natesh Narain <[email protected]> | |
# | |
import subprocess | |
from argparse import ArgumentParser | |
import os | |
parser = ArgumentParser() | |
parser.add_argument('-b', '--bump', required=True, help='major, minor, or patch') | |
parser.add_argument('-i', '--increment', default='1', type=int, help='Increment field by "n"') | |
args = vars(parser.parse_args()) | |
bump = args['bump'] | |
increment = int(args['increment']) | |
# get last git tag | |
proc = subprocess.Popen('git tag', stdout=subprocess.PIPE) | |
version = filter(None, proc.stdout.read().split('\n'))[-1] | |
# get major.minor.patch from current version | |
parts = version.split('.') | |
major = int(parts[0]) | |
minor = int(parts[1]) | |
patch = int(parts[2]) | |
# bump part | |
if bump == 'major': | |
major += increment | |
elif bump == 'minor': | |
minor += increment | |
else: | |
patch += increment | |
new_version = "%d.%d.%d" % (major, minor, patch) | |
print 'Bumping version from %s to %s' % (version, new_version) | |
os.system('git tag -a %s' % (new_version)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment