Merge branch '10998-keepweb-block-cache-size'
[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: debian9)
14 --upload
15     If the build and test steps are successful, upload the packages
16     to a remote apt repository (default: false)
17 --debug
18     Output debug information (default: false)
19 --rc
20     Optional Parameter to build Release Candidate
21 --build-version <version>
22     Version to build (default:
23     \$ARVADOS_BUILDING_VERSION-\$ARVADOS_BUILDING_ITERATION or
24     0.1.timestamp.commithash)
25
26 WORKSPACE=path         Path to the Arvados source tree to build packages from
27
28 EOF
29
30 if ! [[ -n "$WORKSPACE" ]]; then
31   echo >&2 "$helpmessage"
32   echo >&2
33   echo >&2 "Error: WORKSPACE environment variable not set"
34   echo >&2
35   exit 1
36 fi
37
38 if ! [[ -d "$WORKSPACE" ]]; then
39   echo >&2 "$helpmessage"
40   echo >&2
41   echo >&2 "Error: $WORKSPACE is not a directory"
42   echo >&2
43   exit 1
44 fi
45
46 PARSEDOPTS=$(getopt --name "$0" --longoptions \
47     help,debug,upload,rc,target:,build-version: \
48     -- "" "$@")
49 if [ $? -ne 0 ]; then
50     exit 1
51 fi
52
53 TARGET=debian9
54 UPLOAD=0
55 RC=0
56 DEBUG=
57
58 declare -a build_args=()
59
60 eval set -- "$PARSEDOPTS"
61 while [ $# -gt 0 ]; do
62     case "$1" in
63         --help)
64             echo >&2 "$helpmessage"
65             echo >&2
66             exit 1
67             ;;
68         --target)
69             TARGET="$2"; shift
70             ;;
71         --debug)
72             DEBUG=" --debug"
73             ;;
74         --upload)
75             UPLOAD=1
76             ;;
77         --rc)
78             RC=1
79             ;;
80         --build-version)
81             build_args+=("$1" "$2")
82             shift
83             ;;
84         --)
85             if [ $# -gt 1 ]; then
86                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
87                 exit 1
88             fi
89             ;;
90     esac
91     shift
92 done
93
94 build_args+=(--target "$TARGET")
95
96 exit_cleanly() {
97     trap - INT
98     report_outcomes
99     exit ${#failures}
100 }
101
102 COLUMNS=80
103 . $WORKSPACE/build/run-library.sh
104
105 title "Start build packages"
106 timer_reset
107
108 $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}"$DEBUG
109
110 checkexit $? "build packages"
111 title "End of build packages (`timer`)"
112
113 title "Start test packages"
114 timer_reset
115
116 if [ ${#failures[@]} -eq 0 ]; then
117   $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}" --test-packages$DEBUG
118 else
119   echo "Skipping package upload, there were errors building the packages"
120 fi
121
122 checkexit $? "test packages"
123 title "End of test packages (`timer`)"
124
125 if [[ "$UPLOAD" != 0 ]]; then
126   title "Start upload packages"
127   timer_reset
128
129   if [ ${#failures[@]} -eq 0 ]; then
130     if [[ "$RC" != 0 ]]; then
131       echo "/usr/local/arvados-dev/jenkins/run_upload_packages_testing.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
132       /usr/local/arvados-dev/jenkins/run_upload_packages_testing.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
133     else
134       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
135       /usr/local/arvados-dev/jenkins/run_upload_packages.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
136     fi
137   else
138     echo "Skipping package upload, there were errors building and/or testing the packages"
139   fi
140   checkexit $? "upload packages"
141   title "End of upload packages (`timer`)"
142 fi
143
144 exit_cleanly