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