-
Notifications
You must be signed in to change notification settings - Fork 107
/
release.py
64 lines (53 loc) · 1.74 KB
/
release.py
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
#!/usr/bin/python
import sys, getopt
import subprocess
import os
import fileinput
def main(argv):
(releaseVersion, oldVersion) = parseCli(argv)
replaceOldVersion(oldVersion, releaseVersion)
def parseCli(argv):
releaseVersion = None
oldVersion = None
try:
opts, args = getopt.getopt(argv, "r:o:", ["release-version=", "old-version="])
except getopt.GetoptError:
printHelp()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printHelp()
sys.exit()
elif opt in ("-r", "--release-version"):
releaseVersion = arg
elif opt in ("-o", "--old-version"):
oldVersion = arg
if releaseVersion == None:
print("Missing option --release-version:")
printHelp()
sys.exit(2)
if oldVersion == None:
print("Missing option --old-version:")
printHelp()
sys.exit(2)
return (releaseVersion, oldVersion)
def replaceOldVersion(oldVersion, releaseVersion):
for dirpath, dnames, fnames in os.walk("./"):
for f in fnames:
if f.endswith(".md") and not f.startswith("ReleaseNotes"):
filedata = None
with open(os.path.join(dirpath, f), 'r') as file:
filedata = file.read()
filedata = filedata.replace(oldVersion, releaseVersion)
with open(os.path.join(dirpath, f), 'w') as file:
file.write(filedata)
print("Replaced " oldVersion " with " releaseVersion " in file " os.path.join(dirpath, f) ".")
args = ["git", "commit", "-a", "-m", "upgraded version in *.md files to " releaseVersion]
print("Commiting changes: " ' '.join(args))
returncode = subprocess.call(args)
if returncode != 0:
print("Commit failed with error code " str(returncode) ".")
def printHelp():
print("release.py --release-version <release-version> --old-version <old-version>")
if __name__ == "__main__":
main(sys.argv[1:])