Blame


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