-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_release_branches.py
executable file
·232 lines (177 loc) · 6.09 KB
/
create_release_branches.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/local/bin/python
#
# Create new release branch from develop.
#
# - What is this for?
#
# 1. Create new release branch for each sub project.
# 2. Run maven versions to update version number.
# 3. Update properties by sed (this is a hack...)
# 4. Commit all changes
#
import sys
import argparse
import subprocess
import os
targets = ('parent', 'api', 'impl', 'support', 'gui-distribution', 'app-developer')
#
# Reset all local changes and delete release branch.
#
def refresh(version):
p = subprocess.Popen(['git', 'reset', '--hard', "HEAD"],
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p.communicate()
for target in targets:
os.chdir(target)
print(os.getcwd())
p = subprocess.Popen(['git', 'checkout', 'develop'])
out, err = p.communicate()
p = subprocess.Popen(['git', 'branch', '-D', 'release/' + str(version)])
out, err = p.communicate()
p = subprocess.Popen(['git', 'reset', '--hard', "HEAD^"],
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
print out
p = subprocess.Popen(['git', 'clean', '-f'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
print out
if err:
sys.exit(1)
os.chdir("..")
#
# Pull all changes from upstream.
#
def pull():
for target in targets:
print("Module = " + target)
os.chdir(target)
print(os.getcwd())
p = subprocess.Popen(['git', 'pull'],
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
print out
os.chdir("..")
def update_version_numbers(version):
p = subprocess.Popen(['mvn', 'versions:set', '-DnewVersion=' + version],
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
print out
p = subprocess.Popen(['mvn', 'versions:commit'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
print out
return
def build():
p = subprocess.Popen(['mvn', 'clean', 'install'])
out, err = p.communicate()
if err:
print(err)
sys.exit(1)
print out
def branch(version):
new_release_branch = 'release/' + str(version)
for target in targets:
os.chdir(target)
# Checkout develop.
p = subprocess.Popen(['git', 'checkout', 'develop'])
out, err = p.communicate()
if err:
print(err)
sys.exit(1)
p = subprocess.Popen(['git', 'branch', new_release_branch])
out, err = p.communicate()
if err:
print(err)
sys.exit(1)
p = subprocess.Popen(['git', 'checkout', new_release_branch])
out, err = p.communicate()
if err:
print(err)
sys.exit(1)
os.chdir("..")
def update_version(version):
# Set versions from
os.chdir('parent')
p = subprocess.Popen(['mvn', 'versions:set', '-DnewVersion=' + version])
out, err = p.communicate()
if err is not None:
print(err)
sys.exit(1)
os.chdir("..")
# Remove backup files.
for target in targets:
os.chdir(target)
p = subprocess.Popen(['mvn', 'versions:commit'])
out, err = p.communicate()
if err is not None:
print(err)
sys.exit(1)
os.chdir("..")
def update_props(version):
replace = 'find . -name pom.xml | xargs sed -i "" -e \'s/' + version + '-SNAPSHOT/' + version + '/g\''
subprocess.call(replace, shell=True)
def update_develop_props(old_version, next_version):
replace = 'find . -name pom.xml | xargs sed -i "" -e \'s/' + old_version + '-SNAPSHOT/' + next_version + '-SNAPSHOT/g\''
subprocess.call(replace, shell=True)
def commit(message):
for target in targets:
os.chdir(target)
p = subprocess.Popen(['git', 'add', '-A'])
p.communicate()
p = subprocess.Popen(['git', 'commit', '-am', message])
p.communicate()
os.chdir("..")
# main
def main():
print("++ Release Branch Maker ++")
# Parse commandline arguments.
parser = argparse.ArgumentParser()
# Required parameter 1: Cytoscape top directory.
parser.add_argument('-d', '--dir', required=True)
parser.add_argument('-v', '--version', required=True)
parser.add_argument('-n', '--next', required=True)
parser.add_argument('-u', '--update', action="store_true", default=False)
parser.add_argument('-b', '--build', action="store_true", default=False)
parser.add_argument('-r', '--reset', action="store_true", default=False)
args = parser.parse_args()
print("=========== Args ==============")
print(args)
print("===============================")
os.chdir(args.dir)
if args.reset:
print("=========== RESET all local changes ==============")
refresh(args.version)
return
if args.update:
print("=========== Pull everything from upstream ==============")
pull()
if args.build:
print("=========== Build entire Cytoscape project ==============")
build()
return
print("######### Creating new release branches for " + args.version + " #########")
print("Target dir is: " + os.getcwd())
err = branch(args.version)
if err:
print("ERROR!: " + err)
return
# update_version(args.version)
# update_props(args.version)
commit(args.version + ' release branch created.')
# Swicth back to develop
for target in targets:
os.chdir(target)
# Checkout develop.
p = subprocess.Popen(['git', 'checkout', 'develop'])
out, err = p.communicate()
if err:
print(err)
sys.exit(1)
os.chdir("..")
# Finally, update develop's version number
update_version(args.next + '-SNAPSHOT')
update_develop_props(args.version, args.next)
commit('From now on, development branch is for ' + args.next + '.')
# build()
print("=========== Success! Don't forget to commit ==============")
if __name__ == '__main__':
main()