Skip to content

Commit

Permalink
ci: clean azp scripts (#340)
Browse files Browse the repository at this point in the history
##### SUMMARY

Clean old scripts and simplify the CI scripts.
  • Loading branch information
jooola authored Sep 27, 2023
1 parent 3dffaaf commit 001c3e2
Show file tree
Hide file tree
Showing 41 changed files with 185 additions and 490 deletions.
12 changes: 6 additions & 6 deletions .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ variables:
- name: pipelinesCoverage
value: coverage
- name: entryPoint
value: tests/utils/shippable/shippable.sh
value: tests/utils/ci.sh
- name: fetchDepth
value: 0

Expand All @@ -44,7 +44,7 @@ stages:
parameters:
targets:
- name: Sanity
test: devel/sanity/1
test: devel/sanity

- stage: Sanity_2_16
displayName: Sanity 2.16
Expand All @@ -54,7 +54,7 @@ stages:
parameters:
targets:
- name: Sanity
test: 2.16/sanity/1
test: 2.16/sanity

- stage: Sanity_2_15
displayName: Sanity 2.15
Expand All @@ -64,7 +64,7 @@ stages:
parameters:
targets:
- name: Sanity
test: 2.15/sanity/1
test: 2.15/sanity

- stage: Sanity_2_14
displayName: Sanity 2.14
Expand All @@ -74,7 +74,7 @@ stages:
parameters:
targets:
- name: Sanity
test: 2.14/sanity/1
test: 2.14/sanity

- stage: Sanity_2_13
displayName: Sanity 2.13
Expand All @@ -84,7 +84,7 @@ stages:
parameters:
targets:
- name: Sanity
test: 2.13/sanity/1
test: 2.13/sanity

### Units
- stage: Units_devel
Expand Down
14 changes: 7 additions & 7 deletions .azure-pipelines/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -o pipefail -eu

entry_point="$1"
test="$2"
entry_point_args="$2"
read -r -a coverage_branches <<< "$3" # space separated list of branches to run code coverage on for scheduled builds

export COMMIT_MESSAGE
Expand All @@ -16,19 +16,19 @@ if [ "${SYSTEM_PULLREQUEST_TARGETBRANCH:-}" ]; then
IS_PULL_REQUEST=true
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD^2)
else
IS_PULL_REQUEST=
IS_PULL_REQUEST=false
COMMIT_MESSAGE=$(git log --format=%B -n 1 HEAD)
fi

COMPLETE=
COVERAGE=
COMPLETE=false
COVERAGE=false

if [ "${BUILD_REASON}" = "Schedule" ]; then
COMPLETE=yes
COMPLETE=true

if printf '%s\n' "${coverage_branches[@]}" | grep -q "^${BUILD_SOURCEBRANCHNAME}$"; then
COVERAGE=yes
COVERAGE=true
fi
fi

"${entry_point}" "${test}" 2>&1 | "$(dirname "$0")/time-command.py"
"${entry_point}" "${entry_point_args}" 2>&1 | "$(dirname "$0")/time-command.py"
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_certificate/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_certificate_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_datacenter_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_firewall/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_floating_ip/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_floating_ip_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_image_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_iso_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_load_balancer/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_location_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_network/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
disabled
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_network_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_placement_group/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_primary_ip/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_primary_ip_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_rdns/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_route/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group1
azp/group1
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_server/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_server_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_server_network/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
disabled
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_server_type_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_ssh_key/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_ssh_key_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_subnetwork/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group3
azp/group3
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_volume/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
2 changes: 1 addition & 1 deletion tests/integration/targets/hcloud_volume_info/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
shippable/hcloud/group2
azp/group2
141 changes: 141 additions & 0 deletions tests/utils/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash

set -o pipefail -eux

error() {
echo >&2 "error: $*"
exit 1
}

retry() {
local exit_code=1

for _ in 1 2 3; do
set +e
"$@"
exit_code=$?
set -e
if [ $exit_code == 0 ]; then
return $exit_code
fi
done

echo "Command '$*' failed 3 times!"
exit $exit_code
}

declare -a entry_point_args
IFS='/:' read -ra entry_point_args <<< "$1"

# Explode entry point args, for example '2.16/integration/3.10/2' or '2.16/sanity'
ansible_version="${entry_point_args[0]}"
test_name="${entry_point_args[1]}"
python_version="${entry_point_args[2]:-}"
test_group="${entry_point_args[3]:-}"

export PYTHONIOENCODING="utf-8"
export PIP_DISABLE_PIP_VERSION_CHECK=true
export PIP_NO_WARN_SCRIPT_LOCATION=false # Negative options are a bit weird: https://pip.pypa.io/en/stable/topics/configuration/#boolean-options
export ANSIBLE_COLLECTIONS_PATHS="$PWD/../.."

command -v python
python -V

command -v pip
pip --version
pip list

if [ "$ansible_version" == "devel" ]; then
pip install "https://github.com/ansible/ansible/archive/devel.tar.gz"
else
pip install "https://github.com/ansible/ansible/archive/stable-$ansible_version.tar.gz"
fi
command -v ansible
ansible --version

# Prepare coverage args
if $COVERAGE; then
coverage_args="--coverage"
elif [[ "$COMMIT_MESSAGE" =~ ci_coverage ]]; then
coverage_args="--coverage"
else
coverage_args="--coverage-check"
fi

# Prepare changed args
if $COMPLETE; then
changed_args=""
elif [[ "$COMMIT_MESSAGE" =~ ci_complete ]]; then
changed_args=""
else
changed_args="--changed"
fi

# Prepare unstable args
if $IS_PULL_REQUEST; then
unstable_args="--allow-unstable-changed"
else
unstable_args=""
fi

# Install dependencies
pip install rstcheck

# Ensure we can write other collections to this dir
sudo chown "$(whoami)" "$ANSIBLE_COLLECTIONS_PATHS"

pip install -r tests/integration/requirements.txt -c tests/constraints.txt
ansible-galaxy -vvv collection install -r tests/requirements.yml

# Dump env and set timeout
timeout=45
if $COVERAGE; then
timeout=60
fi

ansible-test env --color -v --dump --show --timeout "$timeout"

# Run tests
case "$test_name" in
sanity)
# shellcheck disable=SC2086
ansible-test sanity --color -v \
--exclude plugins/module_utils/vendor/ \
--exclude scripts/ \
--exclude tests/utils/ \
--docker default \
--junit \
$coverage_args \
$changed_args \
--allow-disabled
;;

units)
# shellcheck disable=SC2086
ansible-test units --color -v \
--docker default \
--python "$python_version" \
$coverage_args \
$changed_args
;;

integration)
# shellcheck disable=SC2086
ansible-test integration --color -v \
--remote-terminate always \
--remote-stage prod \
--docker default \
--python "$python_version" \
--retry-on-error \
$coverage_args \
$changed_args \
--changed-all-target none \
--changed-all-mode include \
$unstable_args \
"azp/group$test_group/"
;;

*)
error "found invalid test_name: $test_name"
;;
esac
Loading

0 comments on commit 001c3e2

Please sign in to comment.