Run tox envs separately and capture logs
[releng/global-jjb.git] / shell / tox-run.sh
1 #!/bin/bash
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 # Ensure we fail the job if any steps fail.
14 # DO NOT set -u as virtualenv's activate script has unbound variables
15 set -e -o pipefail
16
17 ARCHIVE_TOX_DIR="$WORKSPACE/archives/tox"
18 mkdir -p "$ARCHIVE_TOX_DIR"
19
20 cd "$WORKSPACE/$TOX_DIR"
21
22 if [ -z "$TOX_ENVS" ]; then
23     TOX_ENVS=$(crudini --get tox.ini tox envlist)
24 fi
25
26 run_tox() {
27     local log_dir="$1"
28     local env="$2"
29
30     echo "-----> Running tox $env"
31     if ! tox -e $env > "$log_dir/tox-$env.log"; then
32         echo "$env" >> "$log_dir/failed-envs.log"
33     fi
34 }
35
36 TOX_ENVS=(${TOX_ENVS//,/ })
37 if hash parallel 2>/dev/null; then
38     export -f run_tox
39     parallel --jobs 200% "run_tox $ARCHIVE_TOX_DIR {}" ::: ${TOX_ENVS[*]}
40 else
41     for env in "${TOX_ENVS[@]}"; do
42         run_tox "$ARCHIVE_TOX_DIR" "$env"
43     done
44 fi
45
46 if [ -f "$ARCHIVE_TOX_DIR/failed-envs.log" ]; then
47     failed_envs=($(cat "$ARCHIVE_TOX_DIR/failed-envs.log"))
48     echo "ERROR: Failed the following builds: ${failed_envs[*]}"
49     exit 1
50 fi
51
52 echo "Completed tox runs."