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