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