Chore: Upgrade Jenkins-job-builder to 6.3.0
[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 # shellcheck disable=SC1090
25 source ~/lf-env.sh
26
27 lf-activate-venv --venv-file /tmp/.toxenv tox virtualenv urllib3~=1.26.15
28
29 if [[ -d /opt/pyenv ]]; then
30     echo "---> Setting up pyenv"
31     export PYENV_ROOT="/opt/pyenv"
32     export PATH="$PYENV_ROOT/bin:$PATH"
33     PYTHONPATH="$(pwd)"
34     export PYTHONPATH
35     export TOX_TESTENV_PASSENV=PYTHONPATH
36 fi
37
38 #Useful debug
39 tox --version
40
41 PARALLEL="${PARALLEL:-true}"
42 TOX_OPTIONS_LIST=""
43
44 if [[ -n ${TOX_ENVS:-} ]]; then
45     TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" -e $TOX_ENVS"
46 fi;
47
48 case ${PARALLEL,,} in
49     true|auto )
50         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel auto --parallel-live";;
51     all )
52         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel all --parallel-live";;
53     [0-9]* )
54         TOX_OPTIONS_LIST=$TOX_OPTIONS_LIST" --parallel ${PARALLEL} --parallel-live";;
55 esac
56
57
58 # $TOX_OPTIONS_LIST are intentionnaly not surrounded by quotes
59 # to correcly pass options to tox
60 # shellcheck disable=SC2086
61 tox $TOX_OPTIONS_LIST | tee -a "$ARCHIVE_TOX_DIR/tox.log"
62 tox_status="${PIPESTATUS[0]}"
63
64 echo "---> Completed tox runs"
65
66 # Disable SC2116 as we want to echo a space separated list of TOX_ENVS
67 # shellcheck disable=SC2116
68 for i in .tox/*/log; do
69     tox_env=$(echo "$i" | awk -F'/' '{print $2}')
70     # defend against glob finding no matches
71     if ! cp -r "$i" "$ARCHIVE_TOX_DIR/$tox_env"; then
72         echo "WARN: no logs found to archive"
73         break
74     fi
75 done
76
77 # If docs are generated push them to archives.
78 DOC_DIR="${DOC_DIR:-docs/_build/html}"
79 if [[ -d $DOC_DIR ]]; then
80     echo "---> Archiving generated docs"
81     mv "$DOC_DIR" "$ARCHIVE_DOC_DIR"
82 fi
83
84 echo "---> tox-run.sh ends"
85
86 test "$tox_status" -eq 0 || exit "$tox_status"