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