crowdsec/test/ansible/prepare-run

50 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
# This loops over all the available boxes, running the test suite on each one.
# The results are collected in a file. If the file already exists, tests are not run again.
env=$1
if [[ -z "${env}" ]]; then
echo "Usage: $0 <env> [vagrant-dir]..."
exit 1
fi
shift
vagrant_dirs=("$@")
if [[ $# -eq 0 ]]; then
2022-08-04 09:25:34 +00:00
# find all targets, with possibly weird names, don't go into subfolders (like 'experimental/')
readarray -d '' vagrant_dirs < <(find vagrant -mindepth 1 -maxdepth 1 -type d -print0 | sort -z | grep -z -v .vagrant)
fi
#shellcheck disable=SC1090
. "${env}"
VAGRANT_FORCE_COLOR=true
export VAGRANT_FORCE_COLOR
for vm in "${vagrant_dirs[@]}"; do
outfile="$(basename "${env}").out"
pushd "${vm}" >/dev/null || exit
2022-08-04 09:25:34 +00:00
if [[ ! -f "Vagrantfile" ]]; then
popd >/dev/null || exit
continue
fi
echo "Prepare and run tests on ${vm}..."
if [[ -x "skip" ]]; then
if ! ./skip; then
popd >/dev/null || exit
continue
fi
fi
if [[ ! -f "${outfile}" ]]; then
vagrant up --no-provision
vagrant provision 2>&1 | tee "${outfile}"
vagrant destroy -f
else
2022-08-04 09:25:34 +00:00
echo "skipping: ${vm}, file ${outfile} already exists." >&2
fi
popd >/dev/null || exit
done