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