issue #14891 upload rcs . Add verbose
[arvados.git] / build / run-build-test-packages-one-target.sh
1 #!/bin/bash -x
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,rc,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         --rc)
69             RC=1
70             ;;    
71         --build-version)
72             build_args+=("$1" "$2")
73             shift
74             ;;
75         --)
76             if [ $# -gt 1 ]; then
77                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
78                 exit 1
79             fi
80             ;;
81     esac
82     shift
83 done
84
85 build_args+=(--target "$TARGET")
86
87 exit_cleanly() {
88     trap - INT
89     report_outcomes
90     exit ${#failures}
91 }
92
93 COLUMNS=80
94 . $WORKSPACE/build/run-library.sh
95
96 title "Start build packages"
97 timer_reset
98
99 $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}"
100
101 checkexit $? "build packages"
102 title "End of build packages (`timer`)"
103
104 title "Start test packages"
105 timer_reset
106
107 if [ ${#failures[@]} -eq 0 ]; then
108   $WORKSPACE/build/run-build-packages-one-target.sh "${build_args[@]}" --test-packages
109 else
110   echo "Skipping package upload, there were errors building the packages"
111 fi
112
113 checkexit $? "test packages"
114 title "End of test packages (`timer`)"
115
116 if [[ "$UPLOAD" != 0 ]]; then
117   title "Start upload packages"
118   timer_reset
119
120   if [ ${#failures[@]} -eq 0 ]; then
121     if [[ "$RC" != 0 ]]; then
122       echo "/usr/local/arvados-dev/jenkins/run_upload_packages_testing.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
123       /usr/local/arvados-dev/jenkins/run_upload_packages_testing.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
124     else
125       echo "/usr/local/arvados-dev/jenkins/run_upload_packages.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET"
126       /usr/local/arvados-dev/jenkins/run_upload_packages.py -H jenkinsapt@apt.arvados.org -o Port=2222 --workspace $WORKSPACE $TARGET
127     fi
128   else
129     echo "Skipping package upload, there were errors building and/or testing the packages"
130   fi
131   checkexit $? "upload packages"
132   title "End of upload packages (`timer`)"
133 fi
134
135 exit_cleanly