1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

Add Gitlab CI

This commit is contained in:
Lukas Kämmerling 2020-04-15 08:35:57 +02:00
parent 363598811e
commit 44a48b6bce
3 changed files with 106 additions and 0 deletions

15
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,15 @@
stages:
- test
test:
stage: test
image: python:3.8-buster
except:
- tags
before_script:
- curl -fsSL https://get.docker.com -o get-docker.sh
- bash get-docker.sh
script:
- bash tests/utils/gitlab/gitlab.sh
tags:
- hc-bladerunner

69
tests/utils/gitlab/gitlab.sh Executable file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -o pipefail -eux
command -v python
python -V
function retry
{
for repetition in 1 2 3; do
set +e
"$@"
result=$?
set -e
if [ ${result} == 0 ]; then
return ${result}
fi
echo "$@ -> ${result}"
done
echo "Command '$@' failed 3 times!"
exit -1
}
command -v pip
pip --version
pip list --disable-pip-version-check
retry pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
export ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible"
SHIPPABLE_RESULT_DIR="$(pwd)/shippable"
TEST_DIR="${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/hetzner/hcloud"
mkdir -p "${TEST_DIR}"
cp -aT "." "${TEST_DIR}"
cd "${TEST_DIR}"
# STAR: HACK install dependencies
retry ansible-galaxy -vvv collection install community.general
retry ansible-galaxy -vvv collection install ansible.netcommon
retry pip install hcloud
# END: HACK
export PYTHONIOENCODING='utf-8'
if [ "${JOB_TRIGGERED_BY_NAME:-}" == "nightly-trigger" ]; then
COMPLETE=yes
fi
if [ -n "${COMPLETE:-}" ]; then
# disable change detection triggered by setting the COMPLETE environment variable to a non-empty value
export CHANGED=""
elif [[ "${CI_COMMIT_MESSAGE}" =~ ci_complete ]]; then
# disable change detection triggered by having 'ci_complete' in the latest commit message
export CHANGED=""
else
# enable change detection (default behavior)
export CHANGED="--changed"
fi
export UNSTABLE="--allow-unstable-changed"
# remove empty core/extras module directories from PRs created prior to the repo-merge
find plugins -type d -empty -print -delete
ansible-test env --dump --show --timeout "50" --color -v
"tests/utils/gitlab/hcloud.sh"

22
tests/utils/gitlab/hcloud.sh Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -o pipefail -eux
cloud="hcloud"
python="3.8"
target="cloud/hcloud"
stage="prod"
changed_all_target="shippable/${cloud}/smoketest/"
if ! ansible-test integration "${changed_all_target}" --list-targets > /dev/null 2>&1; then
# no smoketest tests are available for this cloud
changed_all_target="none"
fi
# shellcheck disable=SC2086
ansible-test integration --color -v --retry-on-error "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} \
--remote-terminate always --remote-stage "${stage}" \
--docker --python "${python}" --changed-all-target "${changed_all_target}""