15028: Fix bashism
[arvados.git] / sdk / cwl / test_with_arvbox.sh
1 #!/bin/sh
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -x
7
8 if ! which arvbox >/dev/null ; then
9     export PATH=$PATH:$(readlink -f $(dirname $0)/../../tools/arvbox/bin)
10 fi
11
12 reset_container=1
13 leave_running=0
14 config=dev
15 tag="latest"
16 pythoncmd=python
17 suite=conformance
18 runapi=containers
19
20 while test -n "$1" ; do
21     arg="$1"
22     case "$arg" in
23         --no-reset-container)
24             reset_container=0
25             shift
26             ;;
27         --leave-running)
28             leave_running=1
29             shift
30             ;;
31         --config)
32             config=$2
33             shift ; shift
34             ;;
35         --tag)
36             tag=$2
37             shift ; shift
38             ;;
39         --build)
40             build=1
41             shift
42             ;;
43         --pythoncmd)
44             pythoncmd=$2
45             shift ; shift
46             ;;
47         --suite)
48             suite=$2
49             shift ; shift
50             ;;
51         --api)
52             runapi=$2
53             shift ; shift
54             ;;
55         -h|--help)
56             echo "$0 [--no-reset-container] [--leave-running] [--config dev|localdemo] [--tag docker_tag] [--build] [--pythoncmd python(2|3)] [--suite (integration|conformance-v1.0|conformance-v1.1)]"
57             exit
58             ;;
59         *)
60             break
61             ;;
62     esac
63 done
64
65 if test -z "$ARVBOX_CONTAINER" ; then
66    export ARVBOX_CONTAINER=cwltest
67 fi
68
69 if test "$suite" = "conformance" ; then
70   suite=conformance-v1.0
71 fi
72
73 if test $reset_container = 1 ; then
74     arvbox stop
75     docker rm $ARVBOX_CONTAINER
76     arvbox reset -f
77 fi
78
79 arvbox start $config $tag
80
81 arvbox pipe <<EOF
82 set -eu -o pipefail
83
84 . /usr/local/lib/arvbox/common.sh
85
86 export PYCMD=$pythoncmd
87
88 if test $config = dev ; then
89   cd /usr/src/arvados/sdk/cwl
90   \$PYCMD setup.py sdist
91   pip_install \$(ls -r dist/arvados-cwl-runner-*.tar.gz | head -n1)
92 fi
93
94 set -x
95
96 if [ \$PYCMD = "python3" ]; then
97     pip3 install cwltest
98 else
99     pip install cwltest
100 fi
101
102 mkdir -p /tmp/cwltest
103 cd /tmp/cwltest
104
105 if [[ "$suite" = "conformance-v1.0" ]] ; then
106    if ! test -d common-workflow-language ; then
107      git clone https://github.com/common-workflow-language/common-workflow-language.git
108    fi
109    cd common-workflow-language
110 elif [[ "$suite" = "conformance-v1.1" ]] ; then
111    if ! test -d cwl-v1.1 ; then
112      git clone https://github.com/common-workflow-language/cwl-v1.1.git
113    fi
114    cd cwl-v1.1
115 fi
116
117 if [[ "$suite" != "integration" ]] ; then
118   git pull
119 fi
120
121 export ARVADOS_API_HOST=localhost:8000
122 export ARVADOS_API_HOST_INSECURE=1
123 export ARVADOS_API_TOKEN=\$(cat /var/lib/arvados/superuser_token)
124
125 if test -n "$build" ; then
126   /usr/src/arvados/build/build-dev-docker-jobs-image.sh
127 elif test "$tag" = "latest" ; then
128   arv-keepdocker --pull arvados/jobs $tag
129 else
130   jobsimg=\$(curl https://versions.arvados.org/v1/commit/$tag | python -c "import json; import sys; sys.stdout.write(json.load(sys.stdin)['Versions']['Docker']['arvados/jobs'])")
131   arv-keepdocker --pull arvados/jobs \$jobsimg
132   docker tag arvados/jobs:\$jobsimg arvados/jobs:latest
133   arv-keepdocker arvados/jobs latest
134 fi
135
136 cat >/tmp/cwltest/arv-cwl-jobs <<EOF2
137 #!/bin/sh
138 exec arvados-cwl-runner --api=jobs \\\$@
139 EOF2
140 chmod +x /tmp/cwltest/arv-cwl-jobs
141
142 cat >/tmp/cwltest/arv-cwl-containers <<EOF2
143 #!/bin/sh
144 exec arvados-cwl-runner --api=containers \\\$@
145 EOF2
146 chmod +x /tmp/cwltest/arv-cwl-containers
147
148 env
149 if [[ "$suite" = "integration" ]] ; then
150    cd /usr/src/arvados/sdk/cwl/tests
151    exec ./arvados-tests.sh $@
152 else
153    exec ./run_test.sh RUNNER=/tmp/cwltest/arv-cwl-${runapi} EXTRA=--compute-checksum $@
154 fi
155 EOF
156
157 CODE=$?
158
159 if test $leave_running = 0 ; then
160     arvbox stop
161 fi
162
163 exit $CODE