19877: Upgrades loofah gem on RailsAPI & Woekbench
[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
35 WORKSPACE=path         Path to the Arvados source tree to build packages from
36
37 EOF
38
39 if ! [[ -n "$WORKSPACE" ]]; then
40   echo >&2 "$helpmessage"
41   echo >&2
42   echo >&2 "Error: WORKSPACE environment variable not set"
43   echo >&2
44   exit 1
45 fi
46
47 if ! [[ -d "$WORKSPACE" ]]; then
48   echo >&2 "$helpmessage"
49   echo >&2
50   echo >&2 "Error: $WORKSPACE is not a directory"
51   echo >&2
52   exit 1
53 fi
54
55 PARSEDOPTS=$(getopt --name "$0" --longoptions \
56     help,debug,upload,rc,target:,force-test,only-build:,force-build,arch:,build-version: \
57     -- "" "$@")
58 if [ $? -ne 0 ]; then
59     exit 1
60 fi
61
62 TARGET=debian10
63 UPLOAD=0
64 RC=0
65 DEBUG=
66
67 declare -a build_args=()
68
69 eval set -- "$PARSEDOPTS"
70 while [ $# -gt 0 ]; do
71     case "$1" in
72         --help)
73             echo >&2 "$helpmessage"
74             echo >&2
75             exit 1
76             ;;
77         --target)
78             TARGET="$2"; shift
79             ;;
80         --force-test)
81             FORCE_TEST=1
82             ;;
83         --force-build)
84             FORCE_BUILD=1
85             ;;
86         --only-build)
87             ONLY_BUILD="$2"; shift
88             ;;
89         --arch)
90             ARCH="$2"; shift
91             ;;
92         --debug)
93             DEBUG=" --debug"
94             ;;
95         --upload)
96             UPLOAD=1
97             ;;
98         --rc)
99             RC=1
100             ;;
101         --build-version)
102             build_args+=("$1" "$2")
103             shift
104             ;;
105         --)
106             if [ $# -gt 1 ]; then
107                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
108                 exit 1
109             fi
110             ;;
111     esac
112     shift
113 done
114
115 build_args+=(--target "$TARGET")
116
117 if [[ -n "$ONLY_BUILD" ]]; then
118   build_args+=(--only-build "$ONLY_BUILD")
119 fi
120
121 if [[ -n "$FORCE_BUILD" ]]; then
122   build_args+=(--force-build)
123 fi
124
125 if [[ -n "$FORCE_TEST" ]]; then
126   build_args+=(--force-test)
127 fi
128
129 if [[ -n "$ARCH" ]]; then
130   build_args+=(--arch "$ARCH")
131 fi
132
133 exit_cleanly() {
134     trap - INT
135     report_outcomes
136     exit ${#failures}
137 }
138
139 COLUMNS=80
140 . $WORKSPACE/build/run-library.sh
141
142 title "Start build packages"
143 timer_reset
144
145 $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}"$DEBUG
146
147 checkexit $? "build packages"
148 title "End of build packages (`timer`)"
149
150 title "Start test packages"
151 timer_reset
152
153 if [ ${#failures[@]} -eq 0 ]; then
154   $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}" --test-packages$DEBUG
155 else
156   echo "Skipping package upload, there were errors building the packages"
157 fi
158
159 checkexit $? "test packages"
160 title "End of test packages (`timer`)"
161
162 if [[ "$UPLOAD" != 0 ]]; then
163   title "Start upload packages"
164   timer_reset
165
166   if [ ${#failures[@]} -eq 0 ]; then
167     if [[ "$RC" != 0 ]]; then
168       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py --repo testing -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
169       /usr/local/arvados-dev/jenkins/run_upload_packages.py --repo testing -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
170     else
171       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py --repo dev -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
172       /usr/local/arvados-dev/jenkins/run_upload_packages.py --repo dev -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
173     fi
174   else
175     echo "Skipping package upload, there were errors building and/or testing the packages"
176   fi
177   checkexit $? "upload packages"
178   title "End of upload packages (`timer`)"
179 fi
180
181 exit_cleanly