/
run-ci.sh
executable file
·195 lines (176 loc) · 5.53 KB
/
run-ci.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
#!/bin/bash
#
# Continuous integration on MiXuP.
#
# This script is meant to be put in a crontab.
cd $(dirname $0)
export OUTDIR=${OUTDIR:-$(pwd)/target/site}
test -d $OUTDIR || mkdir -p $OUTDIR
status() {
log=$1
if tail -n 1 $log | grep -q SUCCESS; then
echo true
else
echo false
fi
}
status_failures_weather() {
ls -1 $OUTDIR/log/log-* | tail -n 6 | while read log; do
if $(status $log); then
echo success
else
echo failure
fi
done | awk 'BEGIN { status=""; count=0; trn=0 } {if ($1 == "failure") { if (status != "" && $1 != status) { trn++ } count+=(6-NR); } status=$1 } END {printf("%d\n", (count/3+trn+.5)/2)}'
}
status_failures_count() {
ls -1 $OUTDIR/log/log-* | tail -n 5 | while read log; do
$(status $log) || echo failure
done | wc -l
}
status_icon() {
case $(status_failures_weather) in
0)
echo ci/weather-clear.png
;;
1)
echo ci/weather-few-clouds.png
;;
2)
echo ci/weather-overcast.png
;;
3)
echo ci/weather-showers-scattered.png
;;
4)
echo ci/weather-showers.png
;;
*)
echo ci/weather-storm.png
;;
esac
}
build_site() {
running=$1
icon=$(status_icon)
failures_count=$(status_failures_count)
echo '<html>'
echo '<head>'
if $running; then
echo '<meta http-equiv="refresh" content="30">'
else
echo '<meta http-equiv="refresh" content="300">'
fi
echo '</head>'
echo '<body>'
echo
echo '<h1>MiXuP continuous integration</h1>'
echo
if [ $failures_count -eq 1 ]; then
echo '<table border="0"><tr><td><img src="'$icon'"></td><td>1 failure in the last 5 builds</td></tr></table>'
else
echo '<table border="0"><tr><td><img src="'$icon'"></td><td>'$failures_count' failures in the last 5 builds</td></tr></table>'
fi
echo
echo '<h2>Build details</h2>'
echo
echo '<table border="0">'
if $running; then
echo '<tr>'
echo '<td>'
echo '<img src="ci/running.png"></td>'
echo '<td colspan="11"><i>Continuous Integration is running</i></td>'
echo '</tr>'
fi
ls -r -1 $OUTDIR/log/log-* | while read log; do
echo '<tr>'
time=$(basename $log | cut -c5- | sed -r 's/^([0-9]{4})([0-9]{2})([0-9]{2})-([0-9]{2})([0-9]{2})([0-9]{2})$/\1-\2-\3 \4:\5:\6/')
buildlog=log/build-$(basename $log)
gitlog=log/git-$(basename $log)
examples=log/examples-$(basename $log)
pkg=release/mixup$(basename $log | cut -c4-).tgz
if $(status $log); then
echo '<td><img src="ci/ok.png"></td>'
else
echo '<td><img src="ci/ko.png"></td>'
fi
echo '<td>'"$time"'</td>'
echo '<td> | </td>'
if [ -e $OUTDIR/$gitlog ]; then
echo '<td><a href="'$gitlog'">git log</a></td>'
else
echo '<td><i>(git log not available)</i></td>'
fi
echo '<td> | </td>'
if [ -d $OUTDIR/$examples ]; then
echo '<td><a href="log/'$(basename $log)'">test log</a></td>'
echo '<td> | </td>'
echo '<td><a href="'$examples'">examples log</a></td>'
else
echo '<td colspan="3"><a href="log/'$(basename $log)'">test log</a></td>'
fi
echo '<td> | </td>'
if [ -e $OUTDIR/$buildlog ]; then
echo '<td><a href="'$buildlog'">release build log</a></td>'
else
echo '<td><i>(release build log not available)</i></td>'
fi
echo '<td> | </td>'
if [ -e $OUTDIR/$pkg ]; then
echo '<td><a href="'$pkg'">download release</a></td>'
else
echo '<td><i>(build not available)</i></td>'
fi
echo '</tr>'
done
echo '</table>'
echo '</body>'
echo '</html>'
}
do_ci() {
git clean -d -f -q -x
lockfile-create --use-pid --lock-name $OUTDIR/ci.lock
lockfile-touch --lock-name $OUTDIR/ci.lock &
BADGER="$!"
test -d $OUTDIR/ci && rm -rf $OUTDIR/ci
cp -R $(pwd)/src/test/ci $OUTDIR/ci
build_site true > $OUTDIR/ci.html
test -d $OUTDIR/log || mkdir $OUTDIR/log
test -d $OUTDIR/release || mkdir $OUTDIR/release
export CI_CLEAN=clean
log=$(nice -n 19 $(pwd)/src/test/eiffel/ci)
cp $log $OUTDIR/log/
buildlog=$OUTDIR/log/build-$(basename $log)
gitlog=$OUTDIR/log/git-$(basename $log)
git log > $gitlog
buildir=$(grep ^TMPDIR= $log | awk -F= '{print $2}')
if [ -d "$buildir" ]; then
builddir=$OUTDIR/log/examples-$(basename $log)
mv $buildir $builddir
fi
if nice -n 19 $(pwd)/release/build.sh -clean > $buildlog; then
pkg=$(grep Done: $buildlog | awk '{print $5}')
test -e $pkg && cp $pkg $OUTDIR/release/mixup$(basename $log | cut -c4-).tgz
else
echo 'Build failed' >> $OUTDIR/log/$(basename $log)
fi
build_site false > $OUTDIR/ci.html
kill "$BADGER"
lockfile-remove --lock-name $OUTDIR/ci.lock
}
lockfile-check --use-pid --lock-name $OUTDIR/ci.lock && exit 0
if git pull | grep -q 'up-to-date'; then
case x$1 in
x-force)
do_ci
;;
*)
if [ -e ./force-ci ]; then
rm -f ./force-ci
do_ci
fi
;;
esac
else
exec ./run-ci.sh -force # should ensure that this script is correctly taken into account when modified
fi