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