-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_difido.py
executable file
·152 lines (123 loc) · 4.52 KB
/
release_difido.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
import os,sys,re,shutil
from common import *
################# Config ##################
DEBUG = False
PROJECT = "difido-reports"
REPOSITORY = "[email protected]:Top-Q/difido-reports.git"
################# Infra ###################
def print_usage():
log("./release.py NEW_RELEASE_VERSION NEW_SNAPSHOT_VERSION")
log("Example:\n ./release.py 6.2.00 6.3.00-SNAPSHOT ")
def getParameters(sys):
new_release_version = sys.argv[1]
new_snapshot_version = sys.argv[2]
if "SNAPSHOT" not in new_snapshot_version:
error("New snapshot version should include suffix -SNAPSHOT")
log("New release version: " + new_release_version)
log("New snapshot version: " + new_snapshot_version)
return new_release_version,new_snapshot_version
################ GIT ####################
def clone():
step("Clonning Difido from the repository")
if os.path.isdir(PROJECT):
report("Found old " + PROJECT + " repository folder. deleting")
execute_command("rm -rf " + PROJECT)
log(f"Clonning {PROJECT} repository")
execute_command("git clone " + REPOSITORY)
os.chdir(PROJECT)
def push():
would_you_like_to_continue("About to push version to remote repository")
step("Pushing changes to remote repository")
if DEBUG:
return
execute_command("git push origin")
execute_command("git push origin --tags")
def tag(new_version):
step("Creating tag for version")
execute_command("git tag -a "+new_version+" -m \"Releasing version "+new_version+"\"")
def commit(message):
step(f"Commiting with message '{message}'")
execute_command(f"git commit -am \"{message}\"")
################ Maven ####################
def deploy():
would_you_like_to_continue("About to deploy artifacts")
step("Deploying artifacts")
if DEBUG:
return
execute_command("mvn clean deploy -f difido-parent/pom.xml -P release -DskipTests=true")
def build():
step(f"Building {PROJECT} version")
execute_command("mvn clean install -f difido-parent/pom.xml -DskipTests=true")
def set_version(old_version,new_version):
replace_versions_in_poms(old_version,new_version)
set_version_in_application_prop(old_version,new_version)
def assert_no_snapshots():
""" We can not relase a version if it is dependent on SNAPSHOT versions """
step("Checking for no snapshot version in POM files")
for dname, dirs, files in os.walk("."):
for fname in files:
if fname != "pom.xml":
continue
fpath = os.path.join(dname, fname)
log("Looking for SNAPSHOT dependency in " + fpath)
with open(fpath) as f:
s = f.read()
if "SNAPSHOT</version>" in s:
error("Found SNAPSHOT version in file: " + fpath + "\n" + s +"\n")
def find_version():
step("Finding the current "+PROJECT+" version")
fname = "difido-parent/pom.xml"
with open(fname) as f:
s = f.read()
m = re.search("<version>([\w|\.-]+)</version>",s)
current_version = m.group(1)
report("Current version: " + current_version)
return current_version
def replace_versions_in_poms(old_version,new_version):
step("Changing version " + old_version + " to " + new_version +" in: ")
for dname, dirs, files in os.walk("."):
for fname in files:
if fname != "pom.xml":
continue
fpath = os.path.join(dname, fname)
with open(fpath) as f:
s = f.read()
replaceStr = "<version>" + old_version + "</version>"
if replaceStr in s:
report(fpath)
s = s.replace(replaceStr, "<version>" + new_version + "</version>")
with open(fpath, "w") as f:
f.write(s)
def set_version_in_application_prop(old_version,new_version):
step("Changing version " + old_version + " to " + new_version +" in application.properties file ")
fpath = "server/difido-server/src/main/resources/config/application.properties"
if not os.path.isfile(fpath):
error("application.properties file was not found in '" + fpath + "'")
with open(fpath) as f:
s = f.read()
replaceStr = "info.app.version=" + old_version
if replaceStr in s:
s = s.replace(replaceStr, "info.app.version=" + new_version)
with open(fpath, "w") as f:
f.write(s)
#####################################
if __name__ == "__main__":
if len(sys.argv) < 3:
report("Not enough parametrs")
print_usage()
sys.exit(0)
new_release_version, new_snapshot_version = getParameters(sys)
clone()
current_version = find_version()
set_version(current_version,new_release_version)
assert_no_snapshots()
build()
commit("Upgrading to version " + new_release_version)
tag(new_release_version)
push()
deploy()
set_version(new_release_version,new_snapshot_version)
commit("Upgrading to version " + new_snapshot_version)
push()
step("Finished Successfully")