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 [-b branch] [-f] [-w worktree ] email-address [email-address ...]"
19 branch=master
20 worktree=$HOME/got
21 force=0
23 args=`getopt b:fw: $*`
24 if [ $? -ne 0 ]
25 then
26 echo "usage: $usage" >&2
27 exit 1
28 fi
29 set -- $args
30 while [ $# -ne 0 ]; do
31 case "$1"
32 in
33 -b)
34 branch="$2"; shift; shift;;
35 -f)
36 force=1; shift;;
37 -w)
38 worktree="$2"; shift; shift;;
39 --)
40 shift; break;;
41 esac
42 done
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"
61 if [ $? -ne 0 ]; then
62 exit 1
63 fi
65 lockfile -r 3 "$lockfile" || exit 1
66 trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM
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" != "0" ]; then
85 mail -s "$prog update failure" $recipients < build.log
86 rm -rf "$lockfile"
87 exit 0
88 fi
89 new_basecommit=`cat .got/base-commit`
91 if [ "$force" != "1" -a "$old_basecommit" == "$new_basecommit" ]; then
92 rm -rf "$lockfile"
93 exit 0
94 fi
96 printf "\n\n\tTesting a regular dev build\n\n" >> build.log
97 log_cmd build.log make obj
98 log_cmd build.log make -j $ncpu
99 build_status="$?"
100 if [ "$build_status" != "0" ]; then
101 mail -s "$prog build failure" $recipients < build.log
102 rm -rf "$lockfile"
103 exit 0
104 fi
105 log_cmd build.log make install
106 log_cmd build.log make -j $ncpu web
107 build_status="$?"
108 if [ "$build_status" != "0" ]; then
109 mail -s "$prog build failure" $recipients < build.log
110 rm -rf "$lockfile"
111 exit 0
112 fi
114 printf "\n\n\tRunning tests\n\n" >> build.log
115 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress
116 regress_status="$?"
117 cat regress.log >> build.log
118 egrep "test.*failed" regress.log > failures.log
119 regress_failure_grep="$?"
120 if [ "$regress_status" != "0" -o "$regress_failure_grep" == "0" ]; then
121 printf "\n\n\t Test failures:\n\n" >> build.log
122 cat failures.log >> build.log
123 mail -s "$prog regress failure" $recipients < build.log
124 rm -rf "$lockfile"
125 exit 0
126 fi
128 printf "\n\n\tTesting a release build\n\n" >> build.log
129 log_cmd build.log make clean
130 log_cmd build.log make obj
131 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes
132 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes web
133 build_status="$?"
134 if [ "$build_status" != "0" ]; then
135 mail -s "$prog release mode build failure" $recipients < build.log
136 rm -rf "$lockfile"
137 exit 0
138 fi
141 rm -f "$lockfile"
142 exit 0