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 [-f] [-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 testroot="/tmp"
25 args=`getopt b:fR:r:w: $*`
26 if [ $? -ne 0 ]
27 then
28 echo "usage: $usage" >&2
29 exit 1
30 fi
31 set -- $args
32 while [ $# -ne 0 ]; do
33 case "$1"
34 in
35 -b)
36 branch="$2"; shift; shift;;
37 -f)
38 force=1; shift;;
39 -w)
40 worktree="$2"; shift; shift;;
41 -r)
42 fromaddr_arg="-r $2"; shift; shift;;
43 -R)
44 testroot="$2"; shift; shift;;
45 --)
46 shift; break;;
47 esac
48 done
50 recipients="$@"
51 if [ -z "$recipients" ]; then
52 echo "usage: $usage" >&2
53 exit 1
54 fi
56 log_cmd() {
57 logfile=$1
58 shift
59 echo \$ $@ >> $logfile
60 $* >> $logfile 2>&1
61 }
63 ncpu=`sysctl -n hw.ncpuonline`
64 lockfile=$worktree/.${prog}.lock
66 cd "$worktree"
67 if [ $? -ne 0 ]; then
68 exit 1
69 fi
71 lockfile -r 3 "$lockfile" || exit 1
72 trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM
74 rm -f regress.log failures.log
75 echo -n "$prog for branch '$branch' on " > build.log
76 date -u >> build.log
78 printf "\nRunning on " >> build.log
79 sysctl -n kern.version >> build.log
81 printf "\n\tCleaning the work tree\n\n" >> build.log
82 log_cmd build.log got status
83 log_cmd build.log make clean
85 printf "\n\n\tUpdating the work tree\n\n" >> build.log
86 log_cmd build.log cat .got/base-commit
87 old_basecommit=`cat .got/base-commit`
88 log_cmd build.log /usr/local/bin/got update -b "$branch"
89 update_status="$?"
90 if [ "$update_status" != "0" ]; then
91 mail $fromaddr_arg -s "$prog update failure" $recipients < build.log
92 rm -rf "$lockfile"
93 exit 0
94 fi
95 new_basecommit=`cat .got/base-commit`
97 if [ "$force" != "1" -a "$old_basecommit" == "$new_basecommit" ]; then
98 rm -rf "$lockfile"
99 exit 0
100 fi
102 printf "\n\n\tTesting a regular dev build\n\n" >> build.log
103 log_cmd build.log make obj
104 log_cmd build.log make -j $ncpu
105 build_status="$?"
106 if [ "$build_status" != "0" ]; then
107 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
108 rm -rf "$lockfile"
109 exit 0
110 fi
111 log_cmd build.log make install
112 log_cmd build.log make -j $ncpu web
113 build_status="$?"
114 if [ "$build_status" != "0" ]; then
115 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
116 rm -rf "$lockfile"
117 exit 0
118 fi
120 printf "\n\n\tRunning tests\n\n" >> build.log
121 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress GOT_TEST_ROOT="$testroot"
122 regress_status="$?"
123 cat regress.log >> build.log
124 egrep "test.*failed" regress.log > failures.log
125 regress_failure_grep="$?"
126 if [ "$regress_status" != "0" -o "$regress_failure_grep" == "0" ]; then
127 printf "\n\n\t Test failures:\n\n" >> build.log
128 cat failures.log >> build.log
129 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
130 rm -rf "$lockfile"
131 exit 0
132 fi
134 printf "\n\n\tRunning tests with pack files\n\n" >> build.log
135 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress GOT_TEST_ROOT="$testroot" GOT_TEST_PACK=1
136 regress_status="$?"
137 cat regress.log >> build.log
138 egrep "test.*failed" regress.log > failures.log
139 regress_failure_grep="$?"
140 if [ "$regress_status" != "0" -o "$regress_failure_grep" == "0" ]; then
141 printf "\n\n\t Test failures:\n\n" >> build.log
142 cat failures.log >> build.log
143 mail $fromaddr_arg -s "$prog regress failure" $recipients < build.log
144 rm -rf "$lockfile"
145 exit 0
146 fi
148 printf "\n\n\tTesting a release build\n\n" >> build.log
149 log_cmd build.log make clean
150 log_cmd build.log make obj
151 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes
152 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes web
153 build_status="$?"
154 if [ "$build_status" != "0" ]; then
155 mail $fromaddr_arg -s "$prog release mode build failure" $recipients < build.log
156 rm -rf "$lockfile"
157 exit 0
158 fi
161 rm -f "$lockfile"
162 exit 0