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