Skip to content

Instantly share code, notes, and snippets.

@OmegaDroid OmegaDroid/
Last active Oct 13, 2017

What would you like to do?
Script for upping the current version tag on a repo
#!/usr/bin/env python
import subprocess
from argparse import ArgumentParser
import re
def parse_args():
parser = ArgumentParser()
parser.add_argument('--dev', '-d', action='store_true')
parser.add_argument('--no-push', action='store_false', dest='push')
return parser.parse_args()
def get_current_versions(stream):
master_re = re.compile(r'^(\d+)\.(\d+)\.(\d+)$')
dev_re = re.compile(r'^(\d+)\.(\d+)\.(\d+)\.dev(\d+)$')
curr_master = None
curr_dev = None
for line in stream.decode().split('\n'):
master_match = master_re.match(line)
dev_match = dev_re.match(line)
if not curr_dev and dev_match:
curr_dev = [int(i) for i in dev_match.groups()]
elif not curr_master and master_match:
curr_master = [int(i) for i in master_match.groups()]
if curr_dev and curr_master:
return (
curr_master or [0, 0, 0],
curr_dev or [0, 0, 0, 0],
def get_next_version(is_dev):
tags_process = subprocess.Popen(['git', 'tag', '--sort=-v:refname'], stdout=subprocess.PIPE)
current_master, current_dev = get_current_versions(tags_process.communicate()[0])
if is_dev:
dev_bit = 'dev{}'.format(current_dev[3] + 1)
if current_master != current_dev[:3]:
dev_bit = 'dev0'
version = current_master + [dev_bit]
current_master[-1] += 1
version = current_master
return '.'.join(str(i) for i in version)
def tag_version(version):
subprocess.check_call(['git', 'tag', '-a', version, '-m', '{}'.format(version)], stdout=subprocess.PIPE)
def push():
subprocess.check_call(['git', 'push', '--tags'], stdout=subprocess.PIPE)
def main():
args = parse_args()
new_version = get_next_version(
if args.push:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.