-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-bump-version
executable file
·89 lines (72 loc) · 2.82 KB
/
git-bump-version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
from __future__ import (
division,
unicode_literals,
print_function,
absolute_import
)
from collections import OrderedDict
import gitcmdutils.semver as semver
import json
import subprocess
import shlex
import argparse
import logging
import sys
def prompt(question):
reply = str(raw_input(question + ' (y/N): ')).lower().strip()
if reply == '':
return False
if reply[0] == 'y':
return True
if reply[0] == 'n':
return False
else:
return prompt("Please enter 'y' or 'n'...")
def main():
parser = \
argparse.ArgumentParser(description='Check that commits are error free with respect to tags and package.json versions')
parser.add_argument('-v', '--verbose', action='store_true',
help='log debug output')
parser.add_argument('-p', '--patch', action='store_true',
help='increment patch version')
parser.add_argument('-m', '--minor', action='store_true',
help='increment minor version')
parser.add_argument('-M', '--major', action='store_true',
help='increment major version')
opts = parser.parse_args(sys.argv[1:])
logging.basicConfig(level=logging.DEBUG if opts.verbose else logging.WARN)
try:
with open('package.json', 'r') as f:
package_json = json.load(f, object_pairs_hook=OrderedDict)
version = package_json['version']
new_tag = ""
if opts.patch:
new_tag = semver.bump_patch(version)
if opts.minor:
new_tag = semver.bump_minor(version)
if opts.major:
new_tag = semver.bump_major(version)
package_json['version'] = new_tag
print(json.dumps(package_json, f, indent=4, sort_keys=False))
print("!!! Changing version from %s to %s !!!" % (version, new_tag))
if prompt("Would you like to push this change?"):
with open('package.json', 'w') as f:
json.dump(package_json, f, indent=4, sort_keys=False)
git_commit_command = "git commit -am \"Bump version\""
git_tag_command = "git tag -a v%s -m v%s" % (new_tag, new_tag)
git_push_command = "git push --tags origin master"
print("Issuing git command: %s" % (git_commit_command))
subprocess.call(shlex.split(git_commit_command))
print("Issuing git command: %s" % (git_tag_command))
subprocess.call(shlex.split(git_tag_command))
print("Issuing git command: %s" % (git_push_command))
subprocess.call(shlex.split(git_push_command))
else:
print("Aborting...")
except Exception, e:
logging.exception(e)
return -1
return 0
if __name__ == '__main__':
sys.exit(main())