Fix OS_CLOUD export for image validation
[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 ARCHIVE_TOX_DIR="$WORKSPACE/archives/tox"
14 mkdir -p "$ARCHIVE_TOX_DIR"
15 cd "$WORKSPACE/$TOX_DIR" || exit 1
16
17 if [ -d "/opt/pyenv" ]; then
18     echo "---> Setting up pyenv"
19     export PYENV_ROOT="/opt/pyenv"
20     export PATH="$PYENV_ROOT/bin:$PATH"
21     PYTHONPATH="$(pwd)"
22     export PYTHONPATH
23     export TOX_TESTENV_PASSENV=PYTHONPATH
24 fi
25
26 PARALLEL="${PARALLEL:-true}"
27 if [ "${PARALLEL}" = true ]; then
28     if [ -n "$TOX_ENVS" ]; then
29         tox -e "$TOX_ENVS" --parallel auto --parallel-live | tee -a "$ARCHIVE_TOX_DIR/tox.log"
30         tox_status="${PIPESTATUS[0]}"
31     else
32         tox --parallel auto --parallel-live | tee -a "$ARCHIVE_TOX_DIR/tox.log"
33         tox_status="${PIPESTATUS[0]}"
34     fi
35 else
36     if [ -n "$TOX_ENVS" ]; then
37         tox -e "$TOX_ENVS" | tee -a "$ARCHIVE_TOX_DIR/tox.log"
38         tox_status="${PIPESTATUS[0]}"
39     else
40         tox | tee -a "$ARCHIVE_TOX_DIR/tox.log"
41         tox_status="${PIPESTATUS[0]}"
42     fi
43 fi
44
45 # Disable SC2116 as we want to echo a space separated list of TOX_ENVS
46 # shellcheck disable=SC2116
47 for i in .tox/*/log; do
48     tox_env=$(echo "$i" | awk -F'/' '{print $2}')
49     cp -r "$i" "$ARCHIVE_TOX_DIR/$tox_env"
50 done
51
52 echo "Completed tox runs."
53
54
55 # If docs are generated push them to archives.
56 DOC_DIR="${DOC_DIR:-docs/_build/html}"
57 if [[ -d "$DOC_DIR" ]]; then
58     echo "---> Archiving generated docs"
59     mv "$DOC_DIR" archives/
60 fi
61
62 test "$tox_status" -eq 0 || exit "$tox_status"