-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildall.sh
executable file
·291 lines (255 loc) · 6.6 KB
/
buildall.sh
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
# Heavily hacked build/release script for MicroWorld
# Expects to be run from the parent directory of the directory which contains all
# the MicroWorld projects.
# WARNING: The regexps in this are fair awfy bruckle. Edit with care.
# Simon Broooke <[email protected]>
# Variable and glag initialisation
archive=FALSE
email=`grep ${USER} /etc/passwd | awk -F\: '{print $5}' | awk -F\, '{print $4}'`
fullname=`grep ${USER} /etc/passwd | awk -F\: '{print $5}' | awk -F\, '{print $1}'`
old="unset"
release=""
tmp=buildall.tmp.$$
trial="FALSE"
webappsdir="/var/lib/tomcat7/webapps"
# Builds the build signature properties in the manifest map file
# expected arguments: old version tag, version tag, full name of user,
# email of user; if not passed, all these will be set to "unset".
# The objective I'm trying to achieve is that when committed to version
# control, these are all always unset; but they're all valid in a build.
function setup-build-sig {
if [ "${1}" = "" ]
then
o="unset"
else
o="${1}"
fi
if [ "${2}" = "" ]
then
v="unset"
else
v="${2}"
fi
if [ "${3}" = "" ]
then
u="unset"
else
u="${3}"
fi
if [ "${4}" = "" ]
then
e="unset"
else
e="${4}"
fi
if [ "${2}${3}${4}" = "" ]
then
t="unset"
i="unset"
else
t=`date --rfc-3339 seconds`
i="${v} built by ${u} on ${t}"
fi
cat <<-EOF > ${tmp}/manifest.sed
s/${o}/${v}/g
s/"build-signature-user" *".*"/"build-signature-user" "${u}"/
s/"build-signature-email" *".*"/"build-signature-email" "${e}"/
s/"build-signature-timestamp" *".*"/"build-signature-timestamp" "${t}"/
s/"build-signature-version" *".*"/"build-signature-version" "${v}"/
s/"Implementation-Version" *".*"/"Implementation-Version" "${i}"/
EOF
}
if [ $# -lt 1 ]
then
cat <<-EOF 1>&2
Usage:
-archive Create a tar archive of the current state of the source.
-build Build all components and commit to master.
-email [ADDRESS] Your email address, to be recorded in the build signature.
-fullname [NAME] Your full name, to be recorded in the build signature.
-pull Pull from remote git repository
-release [LABEL] Build all components, branch for release on old label, then
upversion to new LABEL and commit to master.
-trial Trial build only, do not commit.
-webapps [PATH] Set the path to the local tomcat webapps directory
EOF
exit 1
fi
while (( "$#" ))
do
case $1 in
-a|-archive)
archive="TRUE";;
-b|-build)
# 'build' is the expected normal case.
trial="FALSE";
;;
-e|-email)
shift;
email=$1;;
-f|-fullname)
shift;
fullname=$1;;
-p|-pull)
# pull from remote Git origin
git pull origin master;;
-r|-release)
# release is branch a release and upversion to new label
shift;
release=$1;
trial="FALSE";
if [ "${release}" = "" ]
then
echo "Release flagged, but no release tag supplied" 1>&2;
exit 1;
fi;;
-t|-trial)
trial="TRUE";;
-w|-webapps)
# Set the tomcat webapps directory to release to
shift;
webappsdir=$1;;
*)
echo "Unrecognised option '${1}', exiting." 1>&2;
exit 1;;
esac
shift
done
echo "Trial: ${trial}; email: ${email}; fullname ${fullname}; release: ${release}; webapps: $webappsdir"
ls mw-* > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "No subdirectories matching 'mw-*' found, exiting." 1>&2;
exit 1;
fi
for dir in mw-*
do
pushd ${dir}
# Make a temporary directory to keep the work-in-progress files.
if [ ! -d "${tmp}" ]
then
rm -f "${tmp}"
mkdir "${tmp}"
fi
cat project.clj > ${tmp}/project.bak.1
old=`cat project.clj | grep 'defproject mw' | sed 's/.*defproject mw-[a-z]* "\([A-Za-z0-9_.-]*\)".*/\1/'`
if [ "${release}" != "" ]
then
message="Preparing ${old} for release"
# Does the 'old' version tag end with the token "-SNAPSHOT"? it probably does!
echo "${old}" | grep 'SNAPSHOT'
if [ $? -eq 0 ]
then
# It does...
interim=`echo ${old} | sed 's/\([A-Za-z0-9_.-]*\)-SNAPSHOT.*/\1/'`
if [ "${interim}" = "" ]
then
echo "Failed to compute interim version tag from '${old}'" 1>&2
exit 1;
fi
setup-build-sig "${old}" "${interim}" "${fullname}" "${email}"
message="Upversioned from ${old} to ${interim} for release"
old=${interim}
else
setup-build-sig "unset" "${old}" "${fullname}" "${email}"
fi
else
setup-build-sig "unset" "${old}" "${fullname}" "${email}"
fi
sed -f ${tmp}/manifest.sed ${tmp}/project.bak.1 > project.clj
echo $message
lein clean
lein compile
if [ $? -ne 0 ]
then
echo "Sub-project ${dir} failed in compile" 1>&2
exit 1
fi
lein test
if [ $? -ne 0 ]
then
echo "Sub-project ${dir} failed in test" 1>&2
exit 1
fi
lein marg
lein install
# If we're in the UI project, build the uberwar - and should
# probably deploy it to local Tomcat for test
if [ "${dir}" = "mw-ui" -a "${webappsdir}" != "" ]
then
lein ring uberwar
sudo cp target/microworld.war "${webappsdir}"
echo "Deployed new WAR file to local Tomcat at ${webappsdir}"
fi
# Then unset manifest properties prior to committing.
cat project.clj > ${tmp}/project.bak.2
setup-build-sig
sed -f ${tmp}/manifest.sed ${tmp}/project.bak.2 > project.clj
if [ "${trial}" = "FALSE" ]
then
if [ "${message}" = "" ]
then
git commit -a
else
git commit -a -m "$message"
fi
git push origin master
fi
if [ "${release}" != "" ]
then
branch="${old}_MAINTENANCE"
if [ "${trial}" = "FALSE" ]
then
git branch "${branch}"
git push origin "${branch}"
fi
cat project.clj > ${tmp}/project.bak.3
setup-build-sig "${old}" "${release}-SNAPSHOT" "${fullname}" "${email}"
sed -f ${tmp}/manifest.sed ${tmp}/project.bak.3 > project.clj
message="Upversioned from ${interim} to ${release}-SNAPSHOT"
echo $message
lein clean
lein compile
if [ $? -ne 0 ]
then
echo "Sub-project ${dir} failed in compile after branch to ${release}!" 1>&2
exit 1
fi
lein marg
lein install
# Then unset manifest properties prior to committing.
cat project.clj > ${tmp}/project.bak.4
setup-build-sig
sed -f ${tmp}/manifest.sed ${tmp}/project.bak.4 > project.clj
if [ "${trial}" = "FALSE" ]
then
git commit -a -m "${message}"
echo ${message}
git push origin master
fi
fi
# if nothing broke so far, clean up...
rm -rf "${tmp}"
popd
done
if [ "${archive}" ]
then
for dir in mw-*
do
pushd ${dir}
version=`cat project.clj | grep 'defproject mw' | sed 's/.*defproject mw-[a-z]* "\([A-Za-z0-9_.-]*\)".*/\1/'`
lein clean
popd
done
tmp=microworld-${version}
mkdir ${tmp}
pushd ${tmp}
for dir in ../mw-*
do
cp -r $dir .
done
popd
tar czvf ${tmp}.orig.tar.gz ${tmp}
rm -rf ${tmp}
fi