Merge "Migrate node-verify job to global-jjb"
[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     # Sleep a random 10 second interval to workaround tox sdist
31     # conflicts due to building in the same dist directory.
32     sleep $[ ( $RANDOM % 10 )  + 1 ]s
33
34     echo "-----> Running tox $env"
35     if ! tox -e $env > "$log_dir/tox-$env.log"; then
36         echo "$env" >> "$log_dir/failed-envs.log"
37     fi
38 }
39
40 TOX_ENVS=(${TOX_ENVS//,/ })
41 if hash parallel 2>/dev/null; then
42     export -f run_tox
43     parallel --jobs 200% "run_tox $ARCHIVE_TOX_DIR {}" ::: ${TOX_ENVS[*]}
44 else
45     for env in "${TOX_ENVS[@]}"; do
46         run_tox "$ARCHIVE_TOX_DIR" "$env"
47     done
48 fi
49
50 if [ -f "$ARCHIVE_TOX_DIR/failed-envs.log" ]; then
51     failed_envs=($(cat "$ARCHIVE_TOX_DIR/failed-envs.log"))
52     echo "ERROR: Failed the following builds: ${failed_envs[*]}"
53     exit 1
54 fi
55
56 echo "Completed tox runs."