Tox is called from system python2
[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 ARCHIVE_TOX_DIR="$WORKSPACE/archives/tox"
17 ARCHIVE_DOC_DIR="$WORKSPACE/archives/docs"
18 mkdir -p "$ARCHIVE_TOX_DIR"
19 cd "$WORKSPACE/$TOX_DIR" || exit 1
20
21 if [[ -d /opt/pyenv ]]; then
22     echo "---> Setting up pyenv"
23     export PYENV_ROOT="/opt/pyenv"
24     export PATH="$PYENV_ROOT/bin:$PATH"
25     PYTHONPATH="$(pwd)"
26     export PYTHONPATH
27     export TOX_TESTENV_PASSENV=PYTHONPATH
28 fi
29
30 PARALLEL="${PARALLEL:-true}"
31 if [[ ${PARALLEL,,} = true ]]; then
32     if [[ -n ${TOX_ENVS:-} ]]; then
33         tox -e "$TOX_ENVS" --parallel auto --parallel-live | tee -a "$ARCHIVE_TOX_DIR/tox.log"
34         tox_status="${PIPESTATUS[0]}"
35     else
36         tox --parallel auto --parallel-live | tee -a "$ARCHIVE_TOX_DIR/tox.log"
37         tox_status="${PIPESTATUS[0]}"
38     fi
39 else
40     if [[ -n ${TOX_ENVS:-} ]]; then
41         tox -e "$TOX_ENVS" | tee -a "$ARCHIVE_TOX_DIR/tox.log"
42         tox_status="${PIPESTATUS[0]}"
43     else
44         tox | tee -a "$ARCHIVE_TOX_DIR/tox.log"
45         tox_status="${PIPESTATUS[0]}"
46     fi
47 fi
48
49 echo "---> Completed tox runs"
50
51 # Disable SC2116 as we want to echo a space separated list of TOX_ENVS
52 # shellcheck disable=SC2116
53 for i in .tox/*/log; do
54     tox_env=$(echo "$i" | awk -F'/' '{print $2}')
55     # defend against glob finding no matches
56     if ! cp -r "$i" "$ARCHIVE_TOX_DIR/$tox_env"; then
57         echo "WARN: no logs found to archive"
58         break
59     fi
60 done
61
62 # If docs are generated push them to archives.
63 DOC_DIR="${DOC_DIR:-docs/_build/html}"
64 if [[ -d $DOC_DIR ]]; then
65     echo "---> Archiving generated docs"
66     mv "$DOC_DIR" "$ARCHIVE_DOC_DIR"
67 fi
68
69 echo "---> tox-run.sh ends"
70
71 test "$tox_status" -eq 0 || exit "$tox_status"