CWL script won't fail when there are no documentation changes to commit. no issue #
[arvados-dev.git] / 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 pushd reference
160 python setup.py install
161 python setup.py test
162 ./build-node-docker.sh
163 popd
164
165 pushd conformance
166 pwd
167 ./run_test.sh
168 popd
169
170 cd reference
171 handle_python_package
172
173 ./build-cwl-docker.sh
174
175 if [[ "$UPLOAD_DOCKER" != 0 ]]; then
176     docker push commonworkflowlanguage/cwltool_module
177     docker push commonworkflowlanguage/cwltool
178     docker push commonworkflowlanguage/nodejs-engine
179 fi
180
181 # Setup virtualenv and build documentation.
182
183 virtualenv ../venv
184 . ../venv/bin/activate
185 python setup.py install
186 cd ..
187
188 if test -d common-workflow-language.github.io ; then
189     cd common-workflow-language.github.io
190     git fetch
191     git reset --hard origin/master
192     cd ..
193 else
194     git clone git@github.com:common-workflow-language/common-workflow-language.github.io.git
195     cd common-workflow-language.github.io
196     git config user.email "sysadmin@curoverse.com"
197     git config user.name "Curoverse build bot"
198     cd ..
199 fi
200 python -mcwltool specification/cwlsite.cwl specification/cwlsite-job.json --outdir=$PWD/common-workflow-language.github.io
201 cd common-workflow-language.github.io
202 git add --all
203 git diff-index --quiet HEAD || git commit -m"Build bot"
204 git push