Scripts for buildbot / cloud-init / etc for running tests.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

215 lines
5.9 KiB

#!/usr/bin/env bash
# shellcheck disable=SC1003
# pulled from https://raw.githubusercontent.com/jasperes/bash-yaml/master/script/yaml.sh
# Licensed under MIT license
# Based on https://gist.github.com/pkuczynski/8665367
failure=0
config_file=.travis.yml
parse_yaml() {
local yaml_file=$1
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_.-]*'
fs="$(echo @|tr @ '\034')"
(
sed -e '/- [^\“]'"[^\']"'.*: /s|\([ ]*\)- \([[:space:]]*\)|\1-\'$'\n'' \1\2|g' |
sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
awk -F"$fs" '{
indent = length($1)/2;
if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
}
}' |
sed -e 's/_=/+=/g' |
awk 'BEGIN {
FS="=";
OFS="="
}
/(-|\.).*=/ {
gsub("-|\\.", "_", $1)
}
{ print }'
) < "$yaml_file"
}
create_variables() {
local yaml_file="$1"
local prefix="$2"
eval "$(parse_yaml "$yaml_file" "$prefix")"
}
if [ -n "$1" ]; then
config_file="$1"
fi
if [ ! -e "$config_file" ]; then
echo "No $config_file found, exiting"
exit 1
fi
function aptinstall() {
# apt install
# shellcheck disable=SC2154
if [[ "$(declare -p travis_addons_apt_packages)" =~ "declare -a" ]]; then
if [ -z "$TRAVIS_SKIP_APT_UPDATE" ]; then
echo -e "\nsudo apt -y update\n"
sudo apt -y update
fi
for ((i = 0; i < ${#travis_addons_apt_packages[@]}; i++))
do
echo -e "\napt-get -yq --no-install-suggests --no-install-recommends install ${travis_addons_apt_packages[$i]}\n"
# shellcheck disable=SC2086
sudo apt-get -yq --no-install-suggests --no-install-recommends \
install \
${travis_addons_apt_packages[$i]}
done
fi
}
function pyqt5() {
# install pyqt5 on python > 3
if [[ ! "$TRAVIS_PYTHON" == "2.7" ]]; then
sudo apt -y install qtbase5-dev qt5-default
fi
}
function virtualenv_init() {
# init virtualenv directory
if [ -n "$3" ]; then
echo -e "\nvirtualenv -p \"$1\" \"$3\" ~/.venv-$2\n"
virtualenv -p "$1" "$3" ~/.venv-"$2"
elif [ -n "$2" ]; then
echo -e "\nvirtualenv -p \"$1\" ~/.venv-$2\n"
virtualenv -p "$1" ~/.venv-"$2"
else
echo -e "\nvirtualenv ~/.venv\n"
virtualenv ~/.venv
fi
}
function virtualenv_activate() {
# activate virtualenv
# shellcheck disable=SC1090
if [ -n "$1" ]; then
echo -e "\n. ~/.venv-$1/bin/activate\n"
. ~/.venv-"$1"/bin/activate
else
echo -e "\n. ~/.venv/bin/activate\n"
. ~/.venv/bin/activate
fi
}
function python_run() {
# shellcheck disable=SC2154
if [[ "$(declare -p travis_env)" =~ "declare -a" ]]; then
echo "Setting up environment variables"
for ((i = 0; i < ${#travis_env[@]}; i++))
do
echo -e "\n${travis_env[$i]}\n"
# shellcheck disable=SC2086
export ${travis_env[$i]}
done
fi
# shellcheck disable=SC2154
if [[ "$(declare -p travis_install)" =~ "declare -a" ]]; then
echo "Running \"install\""
if [ -n "$2" ]; then
if [ -e "requirements-${2}.txt" ]; then
echo "Running \"pip install -r requirements-${2}.txt\""
pip install -r "requirements-${2}.txt"
fi
fi
for ((i = 0; i < ${#travis_install[@]}; i++))
do
cd "$rundir" || continue
echo -e "\n${travis_install[$i]}\n"
if ! bash -c "${travis_install[$i]}"; then
failure=1
fi
done
fi
# shellcheck disable=SC2154
if [[ "$(declare -p travis_script)" =~ "declare -a" ]]; then
echo "Running \"script\""
for ((i = 0; i < ${#travis_script[@]}; i++))
do
cd "$rundir" || continue
echo -e "\n${travis_script[$i]}\n"
if ! bash -c "${travis_script[$i]}"; then
failure=1
fi
done
fi
}
create_variables "$config_file" travis_
rundir=$(pwd)
aptinstall
pyqt5
# shellcheck disable=SC2154
if [[ "$(declare -p travis_python)" =~ "declare -a" ]]; then
# shellcheck disable=SC2068
for pv in ${travis_python[@]}; do
# strip quotes
temp="${pv%\"}"
pv="${temp#\"}"
options=$(echo "$pv"|cut -d_ -f2-)
if [ "$options" == "$pv" ]; then
unset options
fi
if [[ "$options" == with* ]]; then
options="--$(echo "$options"|cut -d_ -f2-|tr -- '_' '-')"
fi
pv=$(echo "$pv"|cut -d_ -f1)
ppath=/usr/bin/python$pv
if [ -n "$TRAVIS_PYTHON" ] && [ "$TRAVIS_PYTHON" != "$pv" ]; then
echo "skipping python-$pv due to TRAVIS_PYTHON=$TRAVIS_PYTHON"
continue
fi
if [ ! -e "$ppath" ]; then
sudo apt -y install "python$pv" "python${pv}-dev"
fi
if [ -n "$options" ]; then
virtualenv_init "$ppath" "$pv" "$options"
else
virtualenv_init "$ppath" "$pv"
fi
virtualenv_activate "$pv"
if [[ ! "$TRAVIS_PYTHON" == "2.7" ]]; then
pip install xvfbwrapper
fi
python_run "$ppath" "$pv"
deactivate
done
else
virtualenv_init
virtualenv_activate
python_run
deactivate
fi
exit $failure