| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -o pipefail -eux |
| 4 |
|
| 5 |
error() { |
| 6 |
echo >&2 "error: $*" |
| 7 |
exit 1 |
| 8 |
} |
| 9 |
|
| 10 |
retry() { |
| 11 |
local exit_code=1 |
| 12 |
|
| 13 |
for _ in 1 2 3; do |
| 14 |
set +e |
| 15 |
"$@" |
| 16 |
exit_code=$? |
| 17 |
set -e |
| 18 |
if [ $exit_code == 0 ]; then |
| 19 |
return $exit_code |
| 20 |
fi |
| 21 |
done |
| 22 |
|
| 23 |
echo "Command '$*' failed 3 times!" |
| 24 |
exit $exit_code |
| 25 |
} |
| 26 |
|
| 27 |
declare -a entry_point_args |
| 28 |
IFS='/:' read -ra entry_point_args <<< "$1" |
| 29 |
|
| 30 |
# Explode entry point args, for example '2.16/integration/3.10/2' or '2.16/sanity' |
| 31 |
ansible_version="${entry_point_args[0]}" |
| 32 |
test_name="${entry_point_args[1]}" |
| 33 |
python_version="${entry_point_args[2]:-}" |
| 34 |
test_group="${entry_point_args[3]:-}" |
| 35 |
|
| 36 |
export PYTHONIOENCODING="utf-8" |
| 37 |
export PIP_DISABLE_PIP_VERSION_CHECK=true |
| 38 |
export PIP_NO_WARN_SCRIPT_LOCATION=false # Negative options are a bit weird: https://pip.pypa.io/en/stable/topics/configuration/#boolean-options |
| 39 |
export ANSIBLE_COLLECTIONS_PATH="$PWD/../.." |
| 40 |
|
| 41 |
command -v python |
| 42 |
python -V |
| 43 |
|
| 44 |
command -v pip |
| 45 |
pip --version |
| 46 |
pip list |
| 47 |
|
| 48 |
if [ "$ansible_version" == "devel" ]; then |
| 49 |
pip install "https://github.com/ansible/ansible/archive/devel.tar.gz" |
| 50 |
else |
| 51 |
pip install "https://github.com/ansible/ansible/archive/stable-$ansible_version.tar.gz" |
| 52 |
fi |
| 53 |
command -v ansible |
| 54 |
ansible --version |
| 55 |
|
| 56 |
# Prepare coverage args |
| 57 |
if $COVERAGE; then |
| 58 |
coverage_args="--coverage" |
| 59 |
elif [[ "$COMMIT_MESSAGE" =~ ci_coverage ]]; then |
| 60 |
coverage_args="--coverage" |
| 61 |
else |
| 62 |
coverage_args="--coverage-check" |
| 63 |
fi |
| 64 |
|
| 65 |
# Prepare changed args |
| 66 |
if $COMPLETE; then |
| 67 |
changed_args="" |
| 68 |
elif [[ "$COMMIT_MESSAGE" =~ ci_complete ]]; then |
| 69 |
changed_args="" |
| 70 |
else |
| 71 |
changed_args="--changed" |
| 72 |
fi |
| 73 |
|
| 74 |
# Prepare unstable args |
| 75 |
if $IS_PULL_REQUEST; then |
| 76 |
unstable_args="--allow-unstable-changed" |
| 77 |
else |
| 78 |
unstable_args="" |
| 79 |
fi |
| 80 |
|
| 81 |
# Install dependencies |
| 82 |
pip install rstcheck |
| 83 |
|
| 84 |
# Ensure we can write other collections to this dir |
| 85 |
sudo chown "$(whoami)" "$ANSIBLE_COLLECTIONS_PATH" |
| 86 |
|
| 87 |
pip install -r tests/integration/requirements.txt -c tests/constraints.txt |
| 88 |
ansible-galaxy -vvv collection install -r tests/requirements.yml |
| 89 |
|
| 90 |
# Dump env and set timeout |
| 91 |
timeout=45 |
| 92 |
if $COVERAGE; then |
| 93 |
timeout=60 |
| 94 |
fi |
| 95 |
|
| 96 |
ansible-test env --color -v --dump --show --timeout "$timeout" |
| 97 |
|
| 98 |
# Run tests |
| 99 |
case "$test_name" in |
| 100 |
sanity) |
| 101 |
# shellcheck disable=SC2086 |
| 102 |
ansible-test sanity --color -v \ |
| 103 |
--exclude plugins/module_utils/_vendor/ \ |
| 104 |
--exclude scripts/ \ |
| 105 |
--exclude tests/utils/ \ |
| 106 |
--docker default \ |
| 107 |
--junit \ |
| 108 |
$coverage_args \ |
| 109 |
$changed_args \ |
| 110 |
--allow-disabled |
| 111 |
;; |
| 112 |
|
| 113 |
units) |
| 114 |
# shellcheck disable=SC2086 |
| 115 |
ansible-test units --color -v \ |
| 116 |
--docker default \ |
| 117 |
--python "$python_version" \ |
| 118 |
$coverage_args \ |
| 119 |
$changed_args |
| 120 |
;; |
| 121 |
|
| 122 |
integration) |
| 123 |
# shellcheck disable=SC2086 |
| 124 |
ansible-test integration --color -v \ |
| 125 |
--remote-terminate always \ |
| 126 |
--remote-stage prod \ |
| 127 |
--docker default \ |
| 128 |
--python "$python_version" \ |
| 129 |
--retry-on-error \ |
| 130 |
$coverage_args \ |
| 131 |
$changed_args \ |
| 132 |
--changed-all-target none \ |
| 133 |
--changed-all-mode include \ |
| 134 |
$unstable_args \ |
| 135 |
"azp/group$test_group/" |
| 136 |
;; |
| 137 |
|
| 138 |
*) |
| 139 |
error "found invalid test_name: $test_name" |
| 140 |
;; |
| 141 |
esac |