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