3551: Dry up pass/fail checks with a checkexit() function.
[arvados.git] / jenkins / run-tests.sh
1 #!/bin/bash
2
3 EXITCODE=0
4
5 COLUMNS=80
6
7 ARVADOS_API_HOST=qr1hi.arvadosapi.com
8
9 title () {
10   printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********"
11 }
12
13 source /etc/profile.d/rvm.sh
14 echo $WORKSPACE
15
16 export GOPATH="$HOME/gocode"
17 mkdir -p "$GOPATH/src/git.curoverse.com"
18 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
19
20 # DOCS
21 title "Starting DOC build"
22 cd "$WORKSPACE"
23 cd doc
24 bundle install --deployment
25 rm -rf .site
26 # Make sure python-epydoc is installed or the next line won't do much good!
27 PYTHONPATH=$WORKSPACE/sdk/python/ bundle exec rake generate baseurl=file://$WORKSPACE/doc/.site/ arvados_workbench_host=workbench.$ARVADOS_API_HOST arvados_api_host=$ARVADOS_API_HOST
28
29 checkexit() {
30     ECODE=$?
31
32     if [[ "$ECODE" != "0" ]]; then
33         title "!!!!!! $1 FAILED !!!!!!"
34         EXITCODE=$(($EXITCODE + $ECODE))
35     fi
36 }
37
38 checkexit "Doc build"
39 title "DOC build complete"
40
41 # DOC linkchecker
42 title "Starting DOC linkchecker"
43 cd "$WORKSPACE"
44 cd doc
45 bundle exec rake linkchecker baseurl=file://$WORKSPACE/doc/.site/
46
47 checkexit "Doc linkchecker"
48 title "DOC linkchecker complete"
49
50 # API SERVER
51 title "Starting API server tests"
52 cd "$WORKSPACE"
53 cd services/api
54 bundle install --deployment
55
56 rm -f config/database.yml
57 rm -f config/environments/test.rb
58 cp config/environments/test.rb.example config/environments/test.rb
59
60 # Get test database config
61 cp $HOME/arvados-api-server/database.yml config/
62 # Get test application.yml file
63 cp $HOME/arvados-api-server/application.yml config/
64
65 # Fill in a random secret_token and blob_signing_key for testing
66 SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby`
67 BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby`
68
69 sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml
70 sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml
71
72 export RAILS_ENV=test
73
74 # Set up empty git repo (for git tests)
75 GITDIR=$WORKSPACE/tmpgit
76 rm -rf $GITDIR
77 mkdir $GITDIR
78 sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml
79
80 rm -rf $GITDIR
81 mkdir -p $GITDIR/test
82 cd $GITDIR/test
83 /usr/bin/git init
84 /usr/bin/git config user.email "jenkins@ci.curoverse.com"
85 /usr/bin/git config user.name "Jenkins, CI"
86 touch tmp
87 /usr/bin/git add tmp
88 /usr/bin/git commit -m 'initial commit'
89
90 cd "$WORKSPACE"
91 cd services/api
92
93 bundle exec rake db:drop
94 bundle exec rake db:create
95 bundle exec rake db:setup
96 bundle exec rake test
97
98 checkexit "API server tests"
99 title "API server tests complete"
100
101 # Install and test Go bits. keepstore must come before keepproxy and keepclient.
102 for dir in services/keepstore services/keepproxy sdk/go/arvadosclient sdk/go/keepclient sdk/go/streamer
103 do
104   title "Starting $dir tests"
105   cd "$WORKSPACE"
106
107   go get -t "git.curoverse.com/arvados.git/$dir" \
108   && go test "git.curoverse.com/arvados.git/$dir"
109
110   checkexit "$dir tests"
111   title "$dir tests complete"
112 done
113
114
115 # WORKBENCH
116 title "Starting workbench tests"
117 cd "$WORKSPACE"
118 cd apps/workbench
119 bundle install --deployment
120
121 echo $PATH
122
123
124 bundle exec rake test
125
126 checkexit "Workbench tests"
127 title "Workbench tests complete"
128
129 # Python SDK
130 title "Starting Python SDK tests"
131 cd "$WORKSPACE"
132 cd sdk/cli
133 bundle install --deployment
134
135 # Set up Python SDK and dependencies
136
137 cd "$WORKSPACE"
138 cd sdk/python
139
140 VENVDIR=$(mktemp -d)
141 virtualenv --setuptools "$VENVDIR"
142 "$VENVDIR/bin/python" setup.py test
143
144 checkexit "Python SDK tests"
145
146 "$VENVDIR/bin/python" setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz
147 "$VENVDIR/bin/pip" install dist/arvados-python-client-0.1.*.tar.gz
148
149 checkexit "Python SDK install"
150
151 cd "$WORKSPACE"
152 cd services/fuse
153
154 # We reuse $VENVDIR from the Python SDK tests above
155 "$VENVDIR/bin/python" setup.py test
156
157 checkexit "FUSE tests"
158
159 "$VENVDIR/bin/python" setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 --match .tar.gz
160 "$VENVDIR/bin/pip" install dist/arvados_fuse-0.1.*.tar.gz
161
162 checkexit "FUSE install"
163
164 title "Python SDK tests complete"
165
166 # Clean up $VENVDIR
167 rm -rf "$VENVDIR"
168
169 # The CLI SDK tests require a working API server, so let's skip those for now.
170 exit $EXITCODE
171
172 # CLI SDK
173 title "Starting SDK CLI tests"
174 cd "$WORKSPACE"
175 cd sdk/cli
176 bundle install --deployment
177
178 # Set up Python SDK and dependencies
179 cd ../python
180 rm -rf $HOME/lib/python
181 mkdir $HOME/lib/python
182 PYTHONPATH="$HOME/lib/python" easy_install --install-dir=$HOME/lib/python --upgrade google-api-python-client
183 PYTHONPATH="$HOME/lib/python" python setup.py install --home=$HOME
184
185 cd ../cli
186 mkdir -p /tmp/keep
187 export KEEP_LOCAL_STORE=/tmp/keep
188 PYTHONPATH="$HOME/lib/python" bundle exec rake test
189
190 checkexit "SDK CLI tests"
191 title "SDK CLI tests complete"
192
193 exit $EXITCODE