-
Notifications
You must be signed in to change notification settings - Fork 4
/
bump
executable file
·84 lines (68 loc) · 1.94 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# A simple replacement for the bumpversion Python package that doesn't screw with version control.
import os
import sys
VERSION_FILE = 'abm/VERSION'
def main():
if len(sys.argv) != 2 and len(sys.argv) != 3:
print("USAGE: bump [major|minor|revision|build|release]")
return
if not sys.argv[1] in ['major', 'minor', 'revision', 'build', 'release']:
print("ERROR: Invalid command. Must be one of major, minor, revision, build, or release")
return
with open(VERSION_FILE, 'r') as f:
version_string = f.read().strip()
prefix = version_string
suffix = None
release = None
build = None
if '-' in version_string:
# This is a development build
prefix, suffix = version_string.split('-')
release,build = suffix.split('.')
build = int(build)
parts = prefix.split('.')
major = int(parts[0])
minor = int(parts[1])
revision = int(parts[2])
if sys.argv[1] in ['major', 'minor', 'revision'] and release is not None:
print(f"ERROR: Cannot bump the {sys.argv[1]} version for a development build")
return
if len(sys.argv) == 3:
if build is not None:
print("ERROR: This is already a development build")
return
release = sys.argv[2]
build = 1
type = sys.argv[1]
if type == 'major':
major += 1
minor = 0
revision = 0
elif type == 'minor':
minor += 1
revision = 0
elif type == 'revision':
revision += 1
elif type == 'build':
if build is None:
print(f"ERROR: version {version_string} is not a development build")
return
build += 1
elif type == 'release':
if build is None:
print(f"ERROR: version {version_string} is not a development build")
return
build = None
else:
print(f"BUG: Invalid command {type}")
return
if build is None:
version_string = f"{major}.{minor}.{revision}"
else:
version_string = f"{major}.{minor}.{revision}-{release}.{build}"
with open(VERSION_FILE, 'w') as f:
f.write(version_string)
print(version_string)
if __name__ == '__main__':
main()