-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezrelease.tcl
executable file
·270 lines (223 loc) · 6.13 KB
/
ezrelease.tcl
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/expect
set timeout -1
set red "\033\[1;31m"
set green "\033\[2;32m"
set yellow "\033\[1;33m"
set blue "\033\[1;34m"
set non_color "\033\[;0m"
proc require_input { _msg } {
set red "\033\[1;31m"
set green "\033\[2;32m"
set yellow "\033\[1;33m"
set blue "\033\[1;34m"
set non_color "\033\[;0m"
send_user "${yellow}$_msg${non_color}"
expect_user -re "(.*)\n"
return "$expect_out(1,string)"
}
proc require_input_or_default { _msg _default } {
set red "\033\[1;31m"
set green "\033\[2;32m"
set yellow "\033\[1;33m"
set blue "\033\[1;34m"
set non_color "\033\[;0m"
send_user "${yellow}$_msg: ($_default) :${non_color}"
expect_user -re "(.*)\n"
set _input "$expect_out(1,string)"
if { [string trim $_input] eq "" } {
return $_default
} else {
return $_input
}
}
proc choose { _msg } {
set red "\033\[1;31m"
set green "\033\[2;32m"
set yellow "\033\[1;33m"
set blue "\033\[1;34m"
set non_color "\033\[;0m"
while {true} {
send_user "${yellow}$_msg?(yes/no) ${non_color}"
expect_user -re "(.*)\n"
set _choose "$expect_out(1,string)"
switch $_choose {
"yes" {
return true
}
"no" {
return false
}
}
}
}
proc version_update { _new_version } {
exec mvn versions:set -DnewVersion=$_new_version >@ stdout
}
proc is_all_change_commited {} {
if {[exec git status --porcelain] eq "" } {
return true
} else {
return false
}
}
proc mvn_deploy { } {
catch { exec mvn clean deploy >@ stdout }
}
proc git_commit { _msg } {
exec git add .
exec git commit -m $_msg >@ stdout
}
proc git_commit_submodule { _msg } {
exec git submodule foreach git add .
exec git submodule foreach git commit -m $_msg >@ stdout
}
proc git_tag { _tag _msg } {
exec git tag -a $_tag -m $_msg
}
proc git_tag_submodule { _tag _msg } {
exec git submodule foreach git tag -a $_tag -m $_msg >@ stdout
}
proc git_push_tag { _remote _tag } {
set code [catch { exec git push $_remote $_tag >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
proc git_push_tag_submodule { _remote _tag } {
set code [catch { exec git submodule foreach git push $_remote $_tag >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
proc git_push { _remote _branch } {
set code [catch { exec git push $_remote $_branch >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
proc git_push_submodule { _remote _branch } {
set code [catch { exec git submodule foreach git push $_remote $_branch >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
proc git_change_branch { _branch } {
set code [catch { exec git checkout $_branch >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
proc git_change_branch_submodule { _branch } {
set code [catch { exec git submodule foreach git checkout $_branch >@ stdout } ""]
switch -regexp $code {
[01] {
return true
}
default {
exit 1
}
}
}
if { ![is_all_change_commited] } {
send_user "${red}Can not release when there are some changes not commited.\n${non_color}"
exit 0
}
###########################################################################
# release
set home [pwd]
set pom_location [require_input "Parent pom location: "]
set release_version [require_input "Release version: "]
set is_submodule [choose "Is project a git submodule project"]
set git_remote [require_input_or_default "Git remote: " "origin"]
set git_branch [require_input_or_default "Git branch: " "master"]
set git_remote_branch [require_input_or_default "Git remote branch: " $git_branch]
set git_current_branch [exec git rev-parse --abbrev-ref HEAD]
set release_msg "\[release $release_version by ezrelease\]"
set release_tag "v$release_version"
if { $git_current_branch ne $git_branch } {
if { $is_submodule } {
git_change_branch_submodule $git_branch
}
git_change_branch $git_branch
}
# update version
cd $pom_location
version_update $release_version
mvn_deploy
cd $home
mvn_deploy
# commit & tag
set release_tag "v$release_version"
if { $is_submodule } {
git_commit_submodule $release_msg
git_tag_submodule $release_tag $release_msg
}
git_commit $release_msg
git_tag $release_tag $release_msg
# push commit & tag
set is_push [choose "Push commit"]
if { $is_push } {
if { $is_submodule} {
git_push_submodule $git_remote "$git_branch:$git_remote_branch"
git_push_tag_submodule $git_remote $release_tag
}
git_push $git_remote "$git_branch:$git_remote_branch"
git_push_tag $git_remote $release_tag
}
##################################################################
# new dev version
set new_develop_version [require_input "New develop version: "]
set develop_branch [require_input_or_default "Develop branch: " "dev"]
set remote_develop_branch [require_input_or_default "Remote develop branch: " $develop_branch]
set git_current_branch [exec git rev-parse --abbrev-ref HEAD]
set develop_msg "\[new develop version $new_develop_version by ezrelease\]"
# switch to dev branch
if { $git_current_branch ne $develop_branch } {
if { $is_submodule } {
git_change_branch_submodule $develop_branch
}
git_change_branch $develop_branch
}
# update to new dev version
cd $pom_location
version_update $new_develop_version
mvn_deploy
cd $home
mvn_deploy
# commit
if { $is_submodule } {
git_commit_submodule $develop_msg
}
git_commit $develop_msg
# push commit
if { $is_push } {
if { $is_submodule} {
git_push_submodule $git_remote "$develop_branch:$remote_develop_branch"
}
git_push $git_remote "$develop_branch:$remote_develop_branch"
}