Merge branch 'main' from workbench2.git
[arvados.git] / build / run-build-test-packages-one-target.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 read -rd "\000" helpmessage <<EOF
7 $(basename $0): Build, test and (optionally) upload packages for one target
8
9 Syntax:
10         WORKSPACE=/path/to/arvados $(basename $0) [options]
11
12 --target <target>
13     Distribution to build packages for (default: debian10)
14 --only-build <package>
15     Build only a specific package (or ONLY_BUILD from environment)
16 --arch <arch>
17     Build a specific architecture (or ARCH from environment, defaults to native architecture)
18 --force-build
19     Build even if the package exists upstream or if it has already been
20     built locally
21 --force-test
22     Test even if there is no new untested package
23 --upload
24     If the build and test steps are successful, upload the packages
25     to a remote apt repository (default: false)
26 --debug
27     Output debug information (default: false)
28 --rc
29     Optional Parameter to build Release Candidate
30 --build-version <version>
31     Version to build (default:
32     \$ARVADOS_BUILDING_VERSION-\$ARVADOS_BUILDING_ITERATION or
33     0.1.timestamp.commithash)
34 --skip-docker-build
35     Don't try to build Docker images
36
37 WORKSPACE=path         Path to the Arvados source tree to build packages from
38
39 EOF
40
41 if ! [[ -n "$WORKSPACE" ]]; then
42   echo >&2 "$helpmessage"
43   echo >&2
44   echo >&2 "Error: WORKSPACE environment variable not set"
45   echo >&2
46   exit 1
47 fi
48
49 if ! [[ -d "$WORKSPACE" ]]; then
50   echo >&2 "$helpmessage"
51   echo >&2
52   echo >&2 "Error: $WORKSPACE is not a directory"
53   echo >&2
54   exit 1
55 fi
56
57 PARSEDOPTS=$(getopt --name "$0" --longoptions \
58     help,debug,upload,rc,target:,force-test,only-build:,force-build,arch:,build-version:,skip-docker-build \
59     -- "" "$@")
60 if [ $? -ne 0 ]; then
61     exit 1
62 fi
63
64 TARGET=debian10
65 UPLOAD=0
66 RC=0
67 DEBUG=
68
69 declare -a build_args=()
70
71 eval set -- "$PARSEDOPTS"
72 while [ $# -gt 0 ]; do
73     case "$1" in
74         --help)
75             echo >&2 "$helpmessage"
76             echo >&2
77             exit 1
78             ;;
79         --target)
80             TARGET="$2"; shift
81             ;;
82         --force-test)
83             FORCE_TEST=1
84             ;;
85         --force-build)
86             FORCE_BUILD=1
87             ;;
88         --only-build)
89             ONLY_BUILD="$2"; shift
90             ;;
91         --arch)
92             ARCH="$2"; shift
93             ;;
94         --debug)
95             DEBUG=" --debug"
96             ;;
97         --upload)
98             UPLOAD=1
99             ;;
100         --rc)
101             RC=1
102             ;;
103         --build-version)
104             build_args+=("$1" "$2")
105             shift
106             ;;
107         --skip-docker-build)
108             SKIP_DOCKER_BUILD=1
109             ;;
110         --)
111             if [ $# -gt 1 ]; then
112                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
113                 exit 1
114             fi
115             ;;
116     esac
117     shift
118 done
119
120 build_args+=(--target "$TARGET")
121
122 if [[ -n "$ONLY_BUILD" ]]; then
123   build_args+=(--only-build "$ONLY_BUILD")
124 fi
125
126 if [[ -n "$FORCE_BUILD" ]]; then
127   build_args+=(--force-build)
128 fi
129
130 if [[ -n "$FORCE_TEST" ]]; then
131   build_args+=(--force-test)
132 fi
133
134 if [[ "$SKIP_DOCKER_BUILD" = 1 ]]; then
135   build_args+=(--skip-docker-build)
136 fi
137
138 if [[ -n "$ARCH" ]]; then
139   build_args+=(--arch "$ARCH")
140 fi
141
142 exit_cleanly() {
143     trap - INT
144     report_outcomes
145     exit ${#failures}
146 }
147
148 COLUMNS=80
149 . $WORKSPACE/build/run-library.sh
150
151 title "Start build packages"
152 timer_reset
153
154 $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}"$DEBUG
155
156 checkexit $? "build packages"
157 title "End of build packages (`timer`)"
158
159 title "Start test packages"
160 timer_reset
161
162 if [ ${#failures[@]} -eq 0 ]; then
163   $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}" --test-packages$DEBUG
164 else
165   echo "Skipping package upload, there were errors building the packages"
166 fi
167
168 checkexit $? "test packages"
169 title "End of test packages (`timer`)"
170
171 if [[ "$UPLOAD" != 0 ]]; then
172   title "Start upload packages"
173   timer_reset
174
175   if [ ${#failures[@]} -eq 0 ]; then
176     if [[ "$RC" != 0 ]]; then
177       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py --repo testing -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
178       /usr/local/arvados-dev/jenkins/run_upload_packages.py --repo testing -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
179     else
180       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py --repo dev -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
181       /usr/local/arvados-dev/jenkins/run_upload_packages.py --repo dev -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
182     fi
183   else
184     echo "Skipping package upload, there were errors building and/or testing the packages"
185   fi
186   checkexit $? "upload packages"
187   title "End of upload packages (`timer`)"
188 fi
189
190 exit_cleanly