forked from tv42/gitbuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-build.sh
executable file
·88 lines (73 loc) · 1.63 KB
/
run-build.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
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <commitid>" >&2
echo " Build the tree in build/ as of the given commitid."
exit 1
fi
ref="$1"
mkdir -p out/fail out/pass
chmod 777 out/fail
log()
{
(echo; echo ">>> $@") # log file
}
_run()
{
log "Starting at: $(date)"
commit="$1"
log "Commit: $commit"
cd build || return 10
log "Switching git branch..."
echo --START-IGNORE-WARNINGS
# clobber submodules; git clean won't remove them.
for sub in `git submodule -q foreach pwd`; do
rm -rf $sub
done
git reset --hard HEAD # in case there were modified files
git checkout "$commit" &&
git reset --hard $commit ||
git reset --hard $commit || return 20
echo --STOP-IGNORE-WARNINGS
log "Cleaning..."
git clean -q -f -x -d ||
git clean -q -f -x -d || return 30
log "Building..."
../build.sh 2>&1 || return 40
log "Done at: $(date)"
return 0
}
run()
{
( _run "$@" )
CODE=$?
log "Result code: $CODE"
return $CODE
}
go()
{
echo $ref >out/.doing
rm -f out/pass/$ref out/fail/$ref
run $ref
CODE=${PIPESTATUS[0]}
# This whole program's output is being dumped in log.out. Unix
# lets us rename open files, so we can do that here.
# FIXME: it would be cleaner if the caller renamed the output
# file based on our result code, however.
if [ "$CODE" = 0 ]; then
echo PASS
mv -v out/log out/pass/$ref
else
echo FAIL
mv -v out/log out/fail/$ref
fi
echo "Done: $ref"
rm -f out/.doing
return $CODE
}
set -m
go &
XPID=$!
trap "echo 'Killing (SIGINT)'; kill -TERM -$XPID; exit 1" SIGINT
trap "echo 'Killing (SIGTERM)'; kill -TERM -$XPID; exit 1" SIGTERM
wait $XPID
# return exit code from previous command