-
Notifications
You must be signed in to change notification settings - Fork 9
/
bump
executable file
·70 lines (47 loc) · 1.61 KB
/
bump
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
#!/usr/bin/env python2
"""
A quick and dirty SemVer bump script.
"""
from __future__ import print_function
import argparse
from collections import namedtuple
import re
import sys
parser = argparse.ArgumentParser(description=__doc__)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-m", "--major", action="store_true", default=False, help="Bump the major part.")
group.add_argument("-n", "--minor", action="store_true", default=False, help="Bump the minor part.")
group.add_argument("-p", "--patch", action="store_true", default=False, help="Bump the patch part.")
class Version(namedtuple('Version', ['major', 'minor', 'patch'])):
def bump_patch(self):
return Version(self.major, self.minor, self.patch + 1)
def bump_minor(self):
return Version(self.major, self.minor + 1, 0)
def bump_major(self):
return Version(self.major + 1, 0, 0)
def __str__(self):
return "{0}.{1}.{2}".format(self.major, self.minor, self.patch)
__INITIAL__ = Version(0, 0, 0)
def main(opts):
v = None
try:
with open("VERSION") as f:
v = re.split(re.compile("\\.|-"), f.read()) or __INITIAL__
v = Version(*map(int, v[0:3]))
except ValueError:
print("failed to parse the existing VERSION file, assuming v0.0.0")
v = __INITIAL__
except IOError:
print("failed to find a VERSION file, assuming v0.0.0")
v = __INITIAL__
if opts.major:
v = v.bump_major()
elif opts.minor:
v = v.bump_minor()
elif opts.patch:
v = v.bump_patch()
print(v)
open("VERSION", 'w').write(str(v))
sys.exit(0)
if __name__ == "__main__":
main(parser.parse_args())