3 18f89b62 2020-04-14 stsp # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
5 18f89b62 2020-04-14 stsp # Permission to use, copy, modify, and distribute this software for any
6 18f89b62 2020-04-14 stsp # purpose with or without fee is hereby granted, provided that the above
7 18f89b62 2020-04-14 stsp # copyright notice and this permission notice appear in all copies.
9 18f89b62 2020-04-14 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 18f89b62 2020-04-14 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 18f89b62 2020-04-14 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 18f89b62 2020-04-14 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 18f89b62 2020-04-14 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 18f89b62 2020-04-14 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 18f89b62 2020-04-14 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 18f89b62 2020-04-14 stsp prog=`basename $0`
18 18f89b62 2020-04-14 stsp usage="$prog [-b branch] [-f] [-w worktree ] email-address [email-address ...]"
19 18f89b62 2020-04-14 stsp branch=master
20 18f89b62 2020-04-14 stsp worktree=$HOME/got
23 18f89b62 2020-04-14 stsp args=`getopt b:fw: $*`
24 18f89b62 2020-04-14 stsp if [ $? -ne 0 ]
26 18f89b62 2020-04-14 stsp echo "usage: $usage" >&2
29 18f89b62 2020-04-14 stsp set -- $args
30 18f89b62 2020-04-14 stsp while [ $# -ne 0 ]; do
34 18f89b62 2020-04-14 stsp branch="$2"; shift; shift;;
36 18f89b62 2020-04-14 stsp force=1; shift;;
38 18f89b62 2020-04-14 stsp worktree="$2"; shift; shift;;
40 18f89b62 2020-04-14 stsp shift; break;;
44 18f89b62 2020-04-14 stsp recipients="$@"
45 18f89b62 2020-04-14 stsp if [ -z "$recipients" ]; then
46 18f89b62 2020-04-14 stsp echo "usage: $usage" >&2
53 18f89b62 2020-04-14 stsp echo \$ $@ >> $logfile
54 18f89b62 2020-04-14 stsp $* >> $logfile 2>&1
57 18f89b62 2020-04-14 stsp ncpu=`sysctl -n hw.ncpuonline`
58 18f89b62 2020-04-14 stsp lockfile=$worktree/.${prog}.lock
60 18f89b62 2020-04-14 stsp cd "$worktree"
61 18f89b62 2020-04-14 stsp if [ $? -ne 0 ]; then
65 18f89b62 2020-04-14 stsp lockfile -r 3 "$lockfile" || exit 1
66 18f89b62 2020-04-14 stsp trap "rm -f '$lockfile'" HUP INT QUIT KILL TERM
68 18f89b62 2020-04-14 stsp rm -f regress.log failures.log
69 18f89b62 2020-04-14 stsp echo -n "$prog for branch '$branch' on " > build.log
70 18f89b62 2020-04-14 stsp date -u >> build.log
72 18f89b62 2020-04-14 stsp printf "\nRunning on " >> build.log
73 18f89b62 2020-04-14 stsp sysctl -n kern.version >> build.log
75 18f89b62 2020-04-14 stsp printf "\n\tCleaning the work tree\n\n" >> build.log
76 18f89b62 2020-04-14 stsp log_cmd build.log got status
77 18f89b62 2020-04-14 stsp log_cmd build.log make clean
79 18f89b62 2020-04-14 stsp printf "\n\n\tUpdating the work tree\n\n" >> build.log
80 18f89b62 2020-04-14 stsp log_cmd build.log cat .got/base-commit
81 18f89b62 2020-04-14 stsp old_basecommit=`cat .got/base-commit`
82 18f89b62 2020-04-14 stsp log_cmd build.log /usr/local/bin/got update -b "$branch"
83 18f89b62 2020-04-14 stsp update_status="$?"
84 18f89b62 2020-04-14 stsp if [ "$update_status" != "0" ]; then
85 18f89b62 2020-04-14 stsp mail -s "$prog update failure" $recipients < build.log
86 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
89 18f89b62 2020-04-14 stsp new_basecommit=`cat .got/base-commit`
91 18f89b62 2020-04-14 stsp if [ "$force" != "1" -a "$old_basecommit" == "$new_basecommit" ]; then
92 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
96 18f89b62 2020-04-14 stsp printf "\n\n\tTesting a regular dev build\n\n" >> build.log
97 18f89b62 2020-04-14 stsp log_cmd build.log make obj
98 18f89b62 2020-04-14 stsp log_cmd build.log make -j $ncpu
99 18f89b62 2020-04-14 stsp build_status="$?"
100 18f89b62 2020-04-14 stsp if [ "$build_status" != "0" ]; then
101 18f89b62 2020-04-14 stsp mail -s "$prog build failure" $recipients < build.log
102 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
105 18f89b62 2020-04-14 stsp log_cmd build.log make install
106 18f89b62 2020-04-14 stsp log_cmd build.log make -j $ncpu web
107 18f89b62 2020-04-14 stsp build_status="$?"
108 18f89b62 2020-04-14 stsp if [ "$build_status" != "0" ]; then
109 18f89b62 2020-04-14 stsp mail -s "$prog build failure" $recipients < build.log
110 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
114 18f89b62 2020-04-14 stsp printf "\n\n\tRunning tests\n\n" >> build.log
115 18f89b62 2020-04-14 stsp log_cmd regress.log env PATH=$HOME/bin:$PATH make regress
116 18f89b62 2020-04-14 stsp regress_status="$?"
117 18f89b62 2020-04-14 stsp cat regress.log >> build.log
118 18f89b62 2020-04-14 stsp egrep "test.*failed" regress.log > failures.log
119 18f89b62 2020-04-14 stsp regress_failure_grep="$?"
120 18f89b62 2020-04-14 stsp if [ "$regress_status" != "0" -o "$regress_failure_grep" == "0" ]; then
121 18f89b62 2020-04-14 stsp printf "\n\n\t Test failures:\n\n" >> build.log
122 18f89b62 2020-04-14 stsp cat failures.log >> build.log
123 18f89b62 2020-04-14 stsp mail -s "$prog regress failure" $recipients < build.log
124 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
128 18f89b62 2020-04-14 stsp printf "\n\n\tTesting a release build\n\n" >> build.log
129 18f89b62 2020-04-14 stsp log_cmd build.log make clean
130 18f89b62 2020-04-14 stsp log_cmd build.log make obj
131 bc90a07f 2020-05-05 stsp log_cmd build.log make -j $ncpu GOT_RELEASE=Yes
132 bc90a07f 2020-05-05 stsp log_cmd build.log make -j $ncpu GOT_RELEASE=Yes web
133 18f89b62 2020-04-14 stsp build_status="$?"
134 18f89b62 2020-04-14 stsp if [ "$build_status" != "0" ]; then
135 18f89b62 2020-04-14 stsp mail -s "$prog release mode build failure" $recipients < build.log
136 18f89b62 2020-04-14 stsp rm -rf "$lockfile"
141 18f89b62 2020-04-14 stsp rm -f "$lockfile"