4321ea68ba47760cb2ca104944d7bc8e8e1bf06c
[releng/global-jjb.git] / shell / tox-run.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> tox-run.sh"
12
13 # do not use -o pipefail
14 set -eux
15
16 #Ensure that tox from tox-install.sh takes precedence.
17 PATH=$HOME/.local/bin:$PATH
18
19 ARCHIVE_TOX_DIR="$WORKSPACE/archives/tox"
20 ARCHIVE_DOC_DIR="$WORKSPACE/archives/docs"
21 mkdir -p "$ARCHIVE_TOX_DIR"
22 cd "$WORKSPACE/$TOX_DIR" || exit 1
23
24 if [[ -d /opt/pyenv ]]; then
25     echo "---> Setting up pyenv"
26     export PYENV_ROOT="/opt/pyenv"
27     export PATH="$PYENV_ROOT/bin:$PATH"
28     PYTHONPATH="$(pwd)"
29     export PYTHONPATH
30     export TOX_TESTENV_PASSENV=PYTHONPATH
31 fi
32
33 #Useful debug
34 tox --version
35
36 PARALLEL="${PARALLEL:-true}"
37 TOX_OPTIONS_LIST=""
38
39 if [[ -n ${TOX_ENVS:-} ]]; then
40     TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" -e $TOX_ENVS"
41 fi;
42
43 case ${PARALLEL,,} in
44     true|auto )
45         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel auto --parallel-live";;
46     all )
47         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel all --parallel-live";;
48     [0-9]* )
49         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel ${PARALLEL} --parallel-live";;
50 esac
51
52
53 # $TOX_OPTIONS_LIST are intentionnaly not surrounded by quotes
54 # to correcly pass options to tox
55 # shellcheck disable=SC2086
56 tox $TOX_OPTIONS_LIST | tee -a "$ARCHIVE_TOX_DIR/tox.log"
57 tox_status="${PIPESTATUS[0]}"
58
59 echo "---> Completed tox runs"
60
61 # Disable SC2116 as we want to echo a space separated list of TOX_ENVS
62 # shellcheck disable=SC2116
63 for i in .tox/*/log; do
64     tox_env=$(echo "$i" | awk -F'/' '{print $2}')
65     # defend against glob finding no matches
66     if ! cp -r "$i" "$ARCHIVE_TOX_DIR/$tox_env"; then
67         echo "WARN: no logs found to archive"
68         break
69     fi
70 done
71
72 # If docs are generated push them to archives.
73 DOC_DIR="${DOC_DIR:-docs/_build/html}"
74 if [[ -d $DOC_DIR ]]; then
75     echo "---> Archiving generated docs"
76     mv "$DOC_DIR" "$ARCHIVE_DOC_DIR"
77 fi
78
79 echo "---> tox-run.sh ends"
80
81 test "$tox_status" -eq 0 || exit "$tox_status"