diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..3f9086a --- /dev/null +++ b/.gitlab-ci.yml @@ -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 diff --git a/tests/utils/gitlab/gitlab.sh b/tests/utils/gitlab/gitlab.sh new file mode 100755 index 0000000..36794ba --- /dev/null +++ b/tests/utils/gitlab/gitlab.sh @@ -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" diff --git a/tests/utils/gitlab/hcloud.sh b/tests/utils/gitlab/hcloud.sh new file mode 100755 index 0000000..90651aa --- /dev/null +++ b/tests/utils/gitlab/hcloud.sh @@ -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}""