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