Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 prog=`basename $0`
18 usage="$prog [-fG] [-b branch] [-R testroot] [-r from-address] [-w worktree] email-address ..."
19 branch=main
20 worktree=$HOME/got
21 fromaddr_arg=
22 force=0
23 gotd=0
24 testroot="/tmp"
26 while getopts b:fGR:r:w: arg; do
27 case $arg in
28 b)
29 branch="$OPTARG" ;;
30 f)
31 force=1 ;;
32 G)
33 gotd=1 ;;
34 w)
35 worktree="$OPTARG" ;;
36 r)
37 fromaddr_arg="-r $OPTARG" ;;
38 R)
39 testroot="$OPTARG" ;;
40 ?)
41 echo "usage: $usage" >&2
42 exit 1 ;;
43 esac
44 done
45 shift $(($OPTIND - 1))
47 recipients="$@"
48 if [ -z "$recipients" ]; then
49 echo "usage: $usage" >&2
50 exit 1
51 fi
53 log_cmd() {
54 logfile=$1
55 shift
56 echo \$ $@ >> $logfile
57 $* >> $logfile 2>&1
58 }
60 ncpu=`sysctl -n hw.ncpuonline`
61 lockfile=$worktree/.${prog}.lock
63 cd "$worktree" || exit 1
65 lockfile -r 3 "$lockfile" || exit 1
66 trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM EXIT
68 rm -f regress.log failures.log
69 echo -n "$prog for branch '$branch' on " > build.log
70 date -u >> build.log
72 printf "\nRunning on " >> build.log
73 sysctl -n kern.version >> build.log
75 printf "\n\tCleaning the work tree\n\n" >> build.log
76 log_cmd build.log got status
77 log_cmd build.log make clean
79 printf "\n\n\tUpdating the work tree\n\n" >> build.log
80 log_cmd build.log cat .got/base-commit
81 old_basecommit=`cat .got/base-commit`
82 log_cmd build.log /usr/local/bin/got update -b "$branch"
83 update_status="$?"
84 if [ "$update_status" -ne 0 ]; then
85 mail $fromaddr_arg -s "$prog update failure" $recipients < build.log
86 exit 0
87 fi
88 new_basecommit=`cat .got/base-commit`
90 if [ "$force" -ne 1 -a "$old_basecommit" == "$new_basecommit" ]; then
91 exit 0
92 fi
94 printf "\n\n\tTesting a regular dev build\n\n" >> build.log
95 log_cmd build.log make obj
96 log_cmd build.log make -j $ncpu
97 build_status="$?"
98 if [ "$build_status" -ne 0 ]; then
99 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
100 exit 0
101 fi
102 log_cmd build.log make install
103 log_cmd build.log make -j $ncpu webd
104 build_status="$?"
105 if [ "$build_status" -ne 0 ]; then
106 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
107 exit 0
108 fi
109 log_cmd build.log make -j $ncpu server
110 build_status="$?"
111 if [ "$build_status" -ne 0 ]; then
112 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
113 exit 0
114 fi
115 log_cmd build.log make server-install
117 printf "\n\n\tRunning tests\n\n" >> build.log
118 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress GOT_TEST_ROOT="$testroot"
119 regress_status="$?"
120 cat regress.log >> build.log
121 egrep "test.*failed" regress.log > failures.log
122 regress_failure_grep="$?"
123 if [ "$regress_status" -ne 0 -o "$regress_failure_grep" -eq 0 ]; then
124 printf "\n\n\t Test failures:\n\n" >> build.log
125 cat failures.log >> build.log
126 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
127 exit 0
128 fi
130 printf "\n\n\tRunning tests with pack files\n\n" >> build.log
131 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress GOT_TEST_ROOT="$testroot" GOT_TEST_PACK=1
132 regress_status="$?"
133 cat regress.log >> build.log
134 egrep "test.*failed" regress.log > failures.log
135 regress_failure_grep="$?"
136 if [ "$regress_status" -ne 0 -o "$regress_failure_grep" -eq 0 ]; then
137 printf "\n\n\t Test failures:\n\n" >> build.log
138 cat failures.log >> build.log
139 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
140 exit 0
141 fi
143 printf "\n\n\tRunning tests with pack files using ref-delta\n\n" >> build.log
144 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress GOT_TEST_ROOT="$testroot" GOT_TEST_PACK=ref-delta
145 regress_status="$?"
146 cat regress.log >> build.log
147 egrep "test.*failed" regress.log > failures.log
148 regress_failure_grep="$?"
149 if [ "$regress_status" -ne 0 -o "$regress_failure_grep" -eq 0 ]; then
150 printf "\n\n\t Test failures:\n\n" >> build.log
151 cat failures.log >> build.log
152 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
153 exit 0
154 fi
156 if [ $gotd -ne 0 ]; then
157 printf "\n\n\tRunning gotd tests\n\n" >> build.log
158 log_cmd regress.log doas env PATH=$HOME/bin:$PATH make server-regress
159 regress_status=$?
160 cat regress.log >> build.log
161 egrep "test.*failed" regress.log > failures.log
162 regress_failure_grep="$?"
163 if [ "$regress_status" -ne 0 -o "$regress_failure_grep" -eq 0 ]; then
164 printf "\n\n\t Test failures:\n\n" >> build.log
165 cat failures.log >> build.log
166 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
167 exit 0
168 fi
169 fi
171 printf "\n\n\tTesting a release build\n\n" >> build.log
172 log_cmd build.log make clean
173 log_cmd build.log make obj
174 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes
175 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes webd
176 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes server
177 build_status="$?"
178 if [ "$build_status" -ne 0 ]; then
179 mail $fromaddr_arg -s "$prog release mode build failure" $recipients < build.log
180 exit 0
181 fi
183 exit 0