Loading .gitlab-ci.yml +113 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,116 @@ include: shellcheck-files: "*.sh" bats-enabled: true bats-libraries: "bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip bats-assert@https://github.com/bats-core/bats-assert/archive/v2.0.0.zip" .e2e-scripts: &e2e-scripts | # BEGSCRIPT set -e function log_info() { >&2 echo -e "[\\e[1;94mINFO\\e[0m] $*" } function log_warn() { >&2 echo -e "[\\e[1;93mWARN\\e[0m] $*" } function log_error() { >&2 echo -e "[\\e[1;91mERROR\\e[0m] $*" } function assert_defined() { if [[ -z "${!1}" ]] then log_error "Variable '$1' should be defined" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function refute_defined() { if [[ "${!1}" ]] then log_error "Variable '$1' should not be defined" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function assert_equals() { if [[ "$1" != "$2" ]] then log_error "actual '$2' should be expected '$1'" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function refute_defined() { if [[ "$1" == "$2" ]] then log_error "actual '$2' should not be expected '$1'" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } # ENDSCRIPT e2e: stage: test needs: [] image: $IMAGE parallel: matrix: # - IMAGE: "fedora" - IMAGE: "debian" - IMAGE: "alpine" variables: # enable cache XDG_CACHE_HOME: $CI_PROJECT_DIR/.cache # secrets B64_SECRET: "@b64@YmFzZTY0IHJvY2tzIQo=" HEX_SECRET: "@hex@6865786120697320746865206B6579" URL_SECRET: "@url@$CI_PROJECT_URL/-/raw/$CI_COMMIT_REF_NAME/tests/fixtures/secret.txt" # scoped variables scoped__TESTVAR1__if__CI_JOB_STAGE__equals__test: "stage is 'test'" scoped__TESTVAR2__if__CI_JOB_STAGE__equals__abcde: "stage is 'abcde'" scoped__TESTVAR3__if__CI_JOB_STAGE__in__build__test: "stage is 'build' or 'test'" scoped__TESTVAR4__if__CI_JOB_STAGE__in__package__package_test: "stage is 'package' or 'package-test'" scoped__TESTVAR5__if__CI_JOB_STAGE__startswith__te: "stage starts with 'te'" scoped__TESTVAR6__if__CI_JOB_STAGE__startswith__ab: "stage starts with 'ab'" scoped__TESTVAR7__if__CI_JOB_STAGE__endswith__st: "stage ends with 'st'" scoped__TESTVAR8__if__CI_JOB_STAGE__endswith__de: "stage ends with 'de'" scoped__TESTVAR9__if__CI_JOB_STAGE__contains__es: "stage contains 'es'" scoped__TESTVAR10__if__CI_JOB_STAGE__contains__bcd: "stage contains 'bcd'" cache: key: "$IMAGE-$CI_COMMIT_REF_SLUG" paths: - $XDG_CACHE_HOME when: always before_script: - source tbc_base.sh - source tbc_ca_certs.sh - source tbc_envsubst.sh - source tbc_eval_secrets.sh - source tbc_exec_hook.sh - source tbc_maybe_install_packages.sh - source tbc_unscope_vars.sh - !reference [.e2e-scripts] script: - maybe_install_packages wget ca-certificates git - unscope_variables - assert_equals "stage is 'test'" "$TESTVAR1" - refute_defined TESTVAR2 - assert_equals "stage is 'build' or 'test'" "$TESTVAR3" - refute_defined TESTVAR4 - assert_equals "stage starts with 'te'" "$TESTVAR5" - refute_defined TESTVAR6 - assert_equals "stage ends with 'st'" "$TESTVAR7" - refute_defined TESTVAR8 - assert_equals "stage contains 'es'" "$TESTVAR9" - refute_defined TESTVAR10 - eval_all_secrets - assert_equals "$B64_SECRET" "base64 rocks!" - assert_equals "$HEX_SECRET" "hexa is the key" - assert_equals "$URL_SECRET" "hidden secret" - exit $TBC_TEST_FAILS Loading
.gitlab-ci.yml +113 −0 Original line number Diff line number Diff line Loading @@ -4,3 +4,116 @@ include: shellcheck-files: "*.sh" bats-enabled: true bats-libraries: "bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip bats-assert@https://github.com/bats-core/bats-assert/archive/v2.0.0.zip" .e2e-scripts: &e2e-scripts | # BEGSCRIPT set -e function log_info() { >&2 echo -e "[\\e[1;94mINFO\\e[0m] $*" } function log_warn() { >&2 echo -e "[\\e[1;93mWARN\\e[0m] $*" } function log_error() { >&2 echo -e "[\\e[1;91mERROR\\e[0m] $*" } function assert_defined() { if [[ -z "${!1}" ]] then log_error "Variable '$1' should be defined" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function refute_defined() { if [[ "${!1}" ]] then log_error "Variable '$1' should not be defined" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function assert_equals() { if [[ "$1" != "$2" ]] then log_error "actual '$2' should be expected '$1'" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } function refute_defined() { if [[ "$1" == "$2" ]] then log_error "actual '$2' should not be expected '$1'" TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1)) fi } # ENDSCRIPT e2e: stage: test needs: [] image: $IMAGE parallel: matrix: # - IMAGE: "fedora" - IMAGE: "debian" - IMAGE: "alpine" variables: # enable cache XDG_CACHE_HOME: $CI_PROJECT_DIR/.cache # secrets B64_SECRET: "@b64@YmFzZTY0IHJvY2tzIQo=" HEX_SECRET: "@hex@6865786120697320746865206B6579" URL_SECRET: "@url@$CI_PROJECT_URL/-/raw/$CI_COMMIT_REF_NAME/tests/fixtures/secret.txt" # scoped variables scoped__TESTVAR1__if__CI_JOB_STAGE__equals__test: "stage is 'test'" scoped__TESTVAR2__if__CI_JOB_STAGE__equals__abcde: "stage is 'abcde'" scoped__TESTVAR3__if__CI_JOB_STAGE__in__build__test: "stage is 'build' or 'test'" scoped__TESTVAR4__if__CI_JOB_STAGE__in__package__package_test: "stage is 'package' or 'package-test'" scoped__TESTVAR5__if__CI_JOB_STAGE__startswith__te: "stage starts with 'te'" scoped__TESTVAR6__if__CI_JOB_STAGE__startswith__ab: "stage starts with 'ab'" scoped__TESTVAR7__if__CI_JOB_STAGE__endswith__st: "stage ends with 'st'" scoped__TESTVAR8__if__CI_JOB_STAGE__endswith__de: "stage ends with 'de'" scoped__TESTVAR9__if__CI_JOB_STAGE__contains__es: "stage contains 'es'" scoped__TESTVAR10__if__CI_JOB_STAGE__contains__bcd: "stage contains 'bcd'" cache: key: "$IMAGE-$CI_COMMIT_REF_SLUG" paths: - $XDG_CACHE_HOME when: always before_script: - source tbc_base.sh - source tbc_ca_certs.sh - source tbc_envsubst.sh - source tbc_eval_secrets.sh - source tbc_exec_hook.sh - source tbc_maybe_install_packages.sh - source tbc_unscope_vars.sh - !reference [.e2e-scripts] script: - maybe_install_packages wget ca-certificates git - unscope_variables - assert_equals "stage is 'test'" "$TESTVAR1" - refute_defined TESTVAR2 - assert_equals "stage is 'build' or 'test'" "$TESTVAR3" - refute_defined TESTVAR4 - assert_equals "stage starts with 'te'" "$TESTVAR5" - refute_defined TESTVAR6 - assert_equals "stage ends with 'st'" "$TESTVAR7" - refute_defined TESTVAR8 - assert_equals "stage contains 'es'" "$TESTVAR9" - refute_defined TESTVAR10 - eval_all_secrets - assert_equals "$B64_SECRET" "base64 rocks!" - assert_equals "$HEX_SECRET" "hexa is the key" - assert_equals "$URL_SECRET" "hidden secret" - exit $TBC_TEST_FAILS