forked from siom79/japicmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
116 lines (103 loc) · 3.54 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
import sys, getopt
import subprocess
import os
import fileinput
def main(argv):
(gpgpassphrase, dryRun, devVersion, releaseVersion, releaseTag, oldVersion) = parseCli(argv)
replaceOldVersion(oldVersion, releaseVersion, dryRun)
releaseBuild(gpgpassphrase, dryRun, devVersion, releaseVersion, releaseTag)
def parseCli(argv):
gpgpassphrase = None
dryRun = False
devVersion = None
releaseVersion = None
releaseTag = None
oldVersion = None
try:
opts, args = getopt.getopt(argv, "hg:dn:r:t:o:", ["gpg-passphrase=", "dry-run=", "new-version=", "release-version=", "release-tag=", "old-version="])
except getopt.GetoptError:
printHelp()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printHelp()
sys.exit()
elif opt in ("-g", "--gpg-passphrase"):
gpgpassphrase = arg
elif opt in ("-d", "--dry-run"):
dryRun = True
elif opt in ("-n", "--new-version"):
devVersion = arg
elif opt in ("-r", "--release-version"):
releaseVersion = arg
elif opt in ("-t", "--release-tag"):
releaseTag = arg
elif opt in ("-o", "--old-version"):
oldVersion = arg
if gpgpassphrase == None:
print("Missing option --gpg-passphrase:")
printHelp()
sys.exit(2)
if devVersion == None:
print("Missing option --new-version:")
printHelp()
sys.exit(2)
if releaseVersion == None:
print("Missing option --release-version:")
printHelp()
sys.exit(2)
if releaseTag == None:
print("Missing option --release-tag:")
printHelp()
sys.exit(2)
if oldVersion == None:
print("Missing option --old-version:")
printHelp()
sys.exit(2)
return (gpgpassphrase, dryRun, devVersion, releaseVersion, releaseTag, oldVersion)
def replaceOldVersion(oldVersion, releaseVersion, dryRun):
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))
if not dryRun:
returncode = subprocess.call(args)
if returncode != 0:
print("Commit failed with error code " + str(returncode) + ".")
def releaseBuild(gpgpassphrase, dryRun, devVersion, releaseVersion, releaseTag):
args = ["mvn",
"release:clean",
"release:prepare",
"-DautoVersionSubmodules=true",
"-Dgpg.passphrase=" + gpgpassphrase,
"-DdryRun=" + ("true" if dryRun else "false"),
"-DdevelopmentVersion=" + devVersion,
"-DreleaseVersion=" + releaseVersion,
"-Dtag=" + releaseTag]
print("Executing: " + ' '.join(args))
returncode = subprocess.call(args)
if returncode != 0:
print("Release prepare failed with error code " + str(returncode) + ".")
sys.exit(2)
args = ["mvn",
"release:perform",
"-Dgpg.passphrase=" + gpgpassphrase,
"-DdryRun=" + ("true" if dryRun else "false")]
print("Executing: " + ' '.join(args))
returncode = subprocess.call(args)
if returncode != 0:
print("Release prepare failed with error code " + str(returncode) + ".")
sys.exit(2)
def printHelp():
print("release.py --gpg-passphrase <gpgpassphrase> --dry-run --new-version <new-version> --release-version <release-version> --release-tag <release-tag> --old-version <old-version>")
if __name__ == "__main__":
main(sys.argv[1:])