Commit a94b7460 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

ci: support custom TBC group as an alternative CI/CD configuration

This change restores the working build for basic forking workflow on gitlab.com.
parent 103f3e26
Loading
Loading
Loading
Loading
Loading
+162 −0
Original line number Diff line number Diff line
# Alternative CI/CD configuration file when using TBC in a self-managed GitLab with a custom TBC root group (different from the default "to-be-continuous")
# ℹ️ The CI/CD configuration file can be selected in your project: Settings > CI/CD > General Pipelines > CI/CD Configuration File.
# ⚠️ Requires that the TBC_NAMESPACE variable be set as a server instance variable (recommended), group variable, or project variable.
include:
  - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/bash/gitlab-ci-bash@3.9
    inputs:
      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() {
    val=$(eval echo "\$$1")
    if [[ -z "$val" ]]
    then
      log_error "Variable '$1' should be defined"
      TBC_TEST_FAILS=$((TBC_TEST_FAILS + 1))
    fi
  }

  function refute_defined() {
    val=$(eval echo "\$$1")
    if [[ "$val" ]]
    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

bash-tests:
  stage: test
  needs: []
  image: $IMAGE
  parallel:
    matrix:
      - IMAGE: "fedora"
        SHELLCMD: "bash"
      - IMAGE: "debian"
        SHELLCMD: "bash"
      - IMAGE: "alpine"
        SHELLCMD: "ash"
  script:
    - $SHELLCMD tests/run_tests.sh tests/bash_tests/test_*.sh
  allow_failure: true

e2e-tests:
  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: "applied"
    scoped__TESTVAR2__if__CI_JOB_STAGE__equals__es: "applied"
    scoped__TESTVAR3__if__CI_JOB_STAGE__in__build__test: "applied"
    scoped__TESTVAR4__if__CI_JOB_STAGE__in__package__package_test: "applied"
    scoped__TESTVAR5__if__CI_JOB_STAGE__startswith__te: "applied"
    scoped__TESTVAR6__if__CI_JOB_STAGE__startswith__es: "applied"
    scoped__TESTVAR7__if__CI_JOB_STAGE__endswith__st: "applied"
    scoped__TESTVAR8__if__CI_JOB_STAGE__endswith__es: "applied"
    scoped__TESTVAR9__if__CI_JOB_STAGE__contains__es: "applied"
    scoped__TESTVAR10__ifnot__CI_JOB_STAGE__contains__bcd: "applied"
    scoped__TESTVAR11__ifnot__CI_JOB_STAGE__equals__test: "applied"
    scoped__TESTVAR12__ifnot__CI_JOB_STAGE__equals__es: "applied"
    scoped__TESTVAR13__ifnot__CI_JOB_STAGE__in__build__test: "applied"
    scoped__TESTVAR14__ifnot__CI_JOB_STAGE__in__package__package_test: "applied"
    scoped__TESTVAR15__ifnot__CI_JOB_STAGE__startswith__te: "applied"
    scoped__TESTVAR16__ifnot__CI_JOB_STAGE__startswith__es: "applied"
    scoped__TESTVAR17__ifnot__CI_JOB_STAGE__endswith__st: "applied"
    scoped__TESTVAR18__ifnot__CI_JOB_STAGE__endswith__es: "applied"
    scoped__TESTVAR19__ifnot__CI_JOB_STAGE__contains__es: "applied"
    scoped__TESTVAR20__ifnot__CI_JOB_STAGE__contains__bcd: "applied"
  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 ca-certificates
    - maybe_install_packages wget git

    - unscope_variables
    - assert_defined TESTVAR1
    - refute_defined TESTVAR2
    - assert_defined TESTVAR3
    - refute_defined TESTVAR4
    - assert_defined TESTVAR5
    - refute_defined TESTVAR6
    - assert_defined TESTVAR7
    - refute_defined TESTVAR8
    - assert_defined TESTVAR9
    - refute_defined TESTVAR10

    - refute_defined TESTVAR11
    - assert_defined TESTVAR12
    - refute_defined TESTVAR13
    - assert_defined TESTVAR14
    - refute_defined TESTVAR15
    - assert_defined TESTVAR16
    - refute_defined TESTVAR17
    - assert_defined TESTVAR18
    - refute_defined TESTVAR19
    - assert_defined TESTVAR20

    - 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
+3 −5
Original line number Diff line number Diff line
# Default CI/CD configuration file
# ℹ️ If you're using TBC in a self-managed GitLab with a custom TBC root group, use .gitlab-ci-namespaced.yml instead
include:
  - component: $CI_SERVER_FQDN/$TBC_NAMESPACE/bash/gitlab-ci-bash@3.9
  - component: $CI_SERVER_FQDN/to-be-continuous/bash/gitlab-ci-bash@3.9
    inputs:
      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"

variables:
  # Default value; can be globally overridden
  TBC_NAMESPACE: "to-be-continuous"

.e2e-scripts: &e2e-scripts |
  # BEGSCRIPT
  set -e