Fix detection of version of arvados/jobs image to install.
[arvados-dev.git] / jenkins / run-cwl-tests.sh
1 #!/bin/bash
2
3 # Copyright (C) The Arvados Authors. All rights reserved.
4 #
5 # SPDX-License-Identifier: AGPL-3.0
6
7 read -rd "\000" helpmessage <<EOF
8 $(basename $0): Test cwl tool and (optionally) upload to PyPi and Docker Hub.
9
10 Syntax:
11         WORKSPACE=/path/to/common-workflow-language $(basename $0) [options]
12
13 Options:
14
15 --upload-pypi          Upload package to pypi (default: false)
16 --upload-docker        Upload packages to docker hub (default: false)
17 --debug                Output debug information (default: false)
18
19 WORKSPACE=path         Path to the common-workflow-language source tree
20
21 EOF
22
23 EXITCODE=0
24 CALL_FREIGHT=0
25
26 DEBUG=0
27 UPLOAD_PYPI=0
28 UPLOAD_DOCKER=0
29
30 VENVDIR=
31
32 leave_temp=
33
34 declare -A leave_temp
35
36 set -e
37
38 clear_temp() {
39     leaving=""
40     for var in VENVDIR
41     do
42         if [[ -z "${leave_temp[$var]}" ]]
43         then
44             if [[ -n "${!var}" ]]
45             then
46                 rm -rf "${!var}"
47             fi
48         else
49             leaving+=" $var=\"${!var}\""
50         fi
51     done
52     if [[ -n "$leaving" ]]; then
53         echo "Leaving behind temp dirs: $leaving"
54     fi
55 }
56
57 fatal() {
58     clear_temp
59     echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
60     exit 1
61 }
62
63 trap clear_temp INT EXIT
64
65 # Set up temporary install dirs (unless existing dirs were supplied)
66 for tmpdir in VENVDIR
67 do
68     if [[ -n "${!tmpdir}" ]]; then
69         leave_temp[$tmpdir]=1
70     else
71         eval $tmpdir=$(mktemp -d)
72     fi
73 done
74
75
76 while [[ -n "$1" ]]
77 do
78     arg="$1"; shift
79     case "$arg" in
80         --help)
81             echo >&2 "$helpmessage"
82             echo >&2
83             exit 1
84             ;;
85         --debug)
86             DEBUG=1
87             ;;
88         --upload-pypi)
89             UPLOAD_PYPI=1
90             ;;
91         --upload-docker)
92             UPLOAD_DOCKER=1
93             ;;
94         --leave-temp)
95             leave_temp[VENVDIR]=1
96             ;;
97         *=*)
98             eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
99             ;;
100         *)
101             echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
102             exit 1
103             ;;
104     esac
105 done
106
107 # Sanity check
108 if ! [[ -n "$WORKSPACE" ]]; then
109   echo >&2 "$helpmessage"
110   echo >&2
111   echo >&2 "Error: WORKSPACE environment variable not set"
112   echo >&2
113   exit 1
114 fi
115
116 if [[ "$DEBUG" != 0 ]]; then
117   echo "Workspace is $WORKSPACE"
118 fi
119
120 virtualenv --setuptools "$VENVDIR" || fatal "virtualenv $VENVDIR failed"
121 . "$VENVDIR/bin/activate"
122
123 handle_python_package () {
124   # This function assumes the current working directory is the python package directory
125   if [[ "$UPLOAD_PYPI" != 0 ]]; then
126     # Make sure only to use sdist - that's the only format pip can deal with (sigh)
127     if [[ "$DEBUG" != 0 ]]; then
128       python setup.py sdist upload
129     else
130       python setup.py -q sdist upload
131     fi
132   else
133     # Make sure only to use sdist - that's the only format pip can deal with (sigh)
134     if [[ "$DEBUG" != 0 ]]; then
135       python setup.py sdist
136     else
137       python setup.py -q sdist
138     fi
139   fi
140 }
141
142 # Make all files world-readable -- jenkins runs with umask 027, and has checked
143 # out our git tree here
144 chmod o+r "$WORKSPACE" -R
145
146 # Now fix our umask to something better suited to building and publishing
147 # gems and packages
148 umask 0022
149
150 if [[ "$DEBUG" != 0 ]]; then
151   echo "umask is" `umask`
152 fi
153
154 # Python packages
155 if [[ "$DEBUG" != 0 ]]; then
156   echo
157   echo "Python packages"
158   echo
159 fi
160
161 cd "$WORKSPACE"
162
163 if test -d cwltool ; then
164     (cd cwltool
165      git fetch
166      git reset --hard origin/master
167     )
168 else
169     git clone git@github.com:common-workflow-language/cwltool.git
170     (cd cwltool
171      git config user.email "sysadmin@curoverse.com"
172      git config user.name "Curoverse build bot"
173     )
174 fi
175
176 (cd cwltool
177  python setup.py install
178  python setup.py test
179 )
180
181 ./run_test.sh RUNNER=cwltool DRAFT=draft-2
182 ./run_test.sh RUNNER=cwltool DRAFT=draft-3
183
184 (cd cwltool
185  handle_python_package
186 )
187
188 (cd cwltool/cwl-runner
189  handle_python_package
190 )
191
192 (cd cwltool
193  ./build-cwl-docker.sh
194 )
195
196 if [[ "$UPLOAD_DOCKER" != 0 ]]; then
197     docker push commonworkflowlanguage/cwltool_module
198     docker push commonworkflowlanguage/cwltool
199 fi
200
201 if test -d common-workflow-language.github.io ; then
202     (cd common-workflow-language.github.io
203      git fetch
204      git reset --hard origin/master
205     )
206 else
207     git clone git@github.com:common-workflow-language/common-workflow-language.github.io.git
208     (cd common-workflow-language.github.io
209      git config user.email "sysadmin@curoverse.com"
210      git config user.name "Curoverse build bot"
211     )
212 fi
213
214 cwltool --outdir=$PWD/common-workflow-language.github.io site/cwlsite.cwl site/cwlsite-job.json
215
216 (cd common-workflow-language.github.io
217  git add --all
218  git diff-index --quiet HEAD || git commit -m"Build bot"
219  git push
220 )