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 ] [ -r from-address ] email-address [email-address ...]"
19 branch=master
20 worktree=$HOME/got
21 fromaddr_arg=
22 force=0
24 args=`getopt b:fw:r: $*`
25 if [ $? -ne 0 ]
26 then
27 echo "usage: $usage" >&2
28 exit 1
29 fi
30 set -- $args
31 while [ $# -ne 0 ]; do
32 case "$1"
33 in
34 -b)
35 branch="$2"; shift; shift;;
36 -f)
37 force=1; shift;;
38 -w)
39 worktree="$2"; shift; shift;;
40 -r)
41 fromaddr_arg="-r $2"; shift; shift;;
42 --)
43 shift; break;;
44 esac
45 done
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"
64 if [ $? -ne 0 ]; then
65 exit 1
66 fi
68 lockfile -r 3 "$lockfile" || exit 1
69 trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM
71 rm -f regress.log failures.log
72 echo -n "$prog for branch '$branch' on " > build.log
73 date -u >> build.log
75 printf "\nRunning on " >> build.log
76 sysctl -n kern.version >> build.log
78 printf "\n\tCleaning the work tree\n\n" >> build.log
79 log_cmd build.log got status
80 log_cmd build.log make clean
82 printf "\n\n\tUpdating the work tree\n\n" >> build.log
83 log_cmd build.log cat .got/base-commit
84 old_basecommit=`cat .got/base-commit`
85 log_cmd build.log /usr/local/bin/got update -b "$branch"
86 update_status="$?"
87 if [ "$update_status" != "0" ]; then
88 mail $fromaddr_arg -s "$prog update failure" $recipients < build.log
89 rm -rf "$lockfile"
90 exit 0
91 fi
92 new_basecommit=`cat .got/base-commit`
94 if [ "$force" != "1" -a "$old_basecommit" == "$new_basecommit" ]; then
95 rm -rf "$lockfile"
96 exit 0
97 fi
99 printf "\n\n\tTesting a regular dev build\n\n" >> build.log
100 log_cmd build.log make obj
101 log_cmd build.log make -j $ncpu
102 build_status="$?"
103 if [ "$build_status" != "0" ]; then
104 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
105 rm -rf "$lockfile"
106 exit 0
107 fi
108 log_cmd build.log make install
109 log_cmd build.log make -j $ncpu web
110 build_status="$?"
111 if [ "$build_status" != "0" ]; then
112 mail $fromaddr_arg -s "$prog build failure" $recipients < build.log
113 rm -rf "$lockfile"
114 exit 0
115 fi
117 printf "\n\n\tRunning tests\n\n" >> build.log
118 log_cmd regress.log env PATH=$HOME/bin:$PATH make regress
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" != "0" -o "$regress_failure_grep" == "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 rm -rf "$lockfile"
128 exit 0
129 fi
131 printf "\n\n\tTesting a release build\n\n" >> build.log
132 log_cmd build.log make clean
133 log_cmd build.log make obj
134 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes
135 log_cmd build.log make -j $ncpu GOT_RELEASE=Yes web
136 build_status="$?"
137 if [ "$build_status" != "0" ]; then
138 mail $fromaddr_arg -s "$prog release mode build failure" $recipients < build.log
139 rm -rf "$lockfile"
140 exit 0
141 fi
144 rm -f "$lockfile"
145 exit 0