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