Verified Commit 593e2d87 authored by Adrian DC's avatar Adrian DC
Browse files

ci(gitlab-ci): isolate '.test:template' to 'test.yml' template

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 872a004a
Loading
Loading
Loading
Loading
Loading

.gitlab-ci.d/test.yml

0 → 100644
+61 −0
Changes for .gitlab-ci.d/test.yml: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
spec:
  inputs:
    stage:
      default: test
      description: 'Defines the test stage (Default: test)'
    package:
      default: undefined-package
      description: 'Defines the test package (Default: undefined-package)'
    timeout:
      default: 10m
      description: 'Defines the test timeout (Default: 10m)'
---

.test:template:
  stage: $[[ inputs.stage ]]
  timeout: $[[ inputs.timeout ]]
  variables:
    DEBUG_UPDATES_DISABLE: 'true'
    FORCE_COLOR: 1
    PYTHONUNBUFFERED: 1
    TEMP: .tmp
    TERM: ansi
  before_script:
    # Prepare temporary folder
    - mkdir -p ./.tmp/
    # Install build package
    - |
      if type pipx >/dev/null 2>&1; then
        pipx uninstall $(ls -1 ./dist/*.whl | cut -d'/' -f3 | cut -d'-' -f1) || true
        pipx install --force ./dist/*.whl
      else
        pip3 install ./dist/*.whl
        pip3 install --force-reinstall --no-deps --upgrade ./dist/*.whl
        pip3 show $[[ inputs.package ]]
      fi
  script:
    # Prepare tests
    - export SUITE=$(echo "${SUITE}" | sed 's/,/\\|/g')
    - if [ ! -z "${SUITE}" ]; then ls -1d ./tests/* | grep -q "\/\(${SUITE}\)" || (set +x; echo ' '; echo -e '\033[1;31m[ERROR] The requested SUITE filter does not match any suite\033[0m'; echo ' '; exit 1); fi
    # Prepare sudo access
    - |
      if [ ! -z "${CI_LOCAL_HOST}" ]; then
        (
          set +x
          echo ' '
          echo ' [INFO] Access to "sudo" required during sudo related tests...'
          echo ' '
          sudo echo -n ''
          echo ' '
        )
      fi
    # Run tests
    - for path in $(ls -1d ./tests/* | grep "\/\(${SUITE}\)"); do (cd "${path}/" && time sh ./test.sh 2>&1); done
    # Finish tests
    - |
      (
        set +x
        echo ' '
        echo ' [INFO] Unit tests finished successfully'
        echo ' '
      )
+15 −48
Changes for .gitlab-ci.yml: 15 added lines, 48 removed lines.
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ include:
  - local: .gitlab-ci.d/readme.yml
    inputs:
      stage: build
  - local: .gitlab-ci.d/test.yml
    inputs:
      stage: test
      package: gitlab-projects-settings
      timeout: 10m
  - local: .gitlab-ci.d/quality.yml
    inputs:
      stage: quality
@@ -268,10 +273,7 @@ build:
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      when: on_success

# =============================================================================
# Stage: test (templates)

.unit-tests-rules:
.test:rules:
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
      changes:
@@ -281,41 +283,6 @@ build:
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      when: on_success

.unit-tests-template:
  stage: test
  timeout: 10m
  variables:
    DEBUG_UPDATES_DISABLE: 'true'
    FORCE_COLOR: 1
    PYTHONUNBUFFERED: 1
    TEMP: .tmp
    TERM: ansi
  before_script:
    - mkdir -p ./.tmp/
    - |
      if type pipx >/dev/null 2>&1; then
        pipx uninstall $(ls -1 ./dist/*.whl | cut -d'/' -f3 | cut -d'-' -f1) || true
        pipx install --force ./dist/*.whl
      else
        pip3 install ./dist/*.whl
        pip3 install --force-reinstall --no-deps --upgrade ./dist/*.whl
        pip3 show gitlab-projects-settings
      fi
  script:
    # Prepare tests
    - export SUITE=$(echo "${SUITE}" | sed 's/,/\\|/g')
    - if [ ! -z "${SUITE}" ]; then ls -1d ./tests/* | grep -q "\/\(${SUITE}\)" || (set +x; echo ' '; echo -e '\033[1;31m[ERROR] The requested SUITE filter does not match any suite\033[0m'; echo ' '; exit 1); fi
    # Run tests
    - for path in $(ls -1d ./tests/* | grep "\/\(${SUITE}\)"); do (cd "${path}/" && time sh ./test.sh 2>&1); done
    # Finish tests
    - |
      (
        set +x
        echo ' '
        echo ' [INFO] Unit tests finished successfully'
        echo ' '
      )

.coverage-scripts:
  variables:
    COVERAGE_COMMON_FILE: ${CI_PROJECT_DIR}/coverage-reports/.coverage-common
@@ -357,14 +324,14 @@ build:

.coverage-template:
  extends:
    - .unit-tests-template
    - .unit-tests-rules
    - .test:template
    - .test:rules
    - .coverage-scripts
  variables:
    PYTHONDONTWRITEBYTECODE: 1
    PYTHONPATH: ${CI_PROJECT_DIR}
  script:
    - !reference [.unit-tests-template, script]
    - !reference ['.test:template', script]
    - !reference [.coverage-scripts, script]
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
@@ -422,19 +389,19 @@ coverage:windows:

py3.8:
  extends:
    - .unit-tests-template
    - .unit-tests-rules
    - .test:template
    - .test:rules
  image: registry.gitlab.com/radiandevcore/tools/gitlab-projects-settings/gitlab-projects-settings:test-oldest
  before_script:
    - !reference [.unit-tests-template, before_script]
    - !reference ['.test:template', before_script]

py3.12:
  extends:
    - .unit-tests-template
    - .unit-tests-rules
    - .test:template
    - .test:rules
  image: registry.gitlab.com/radiandevcore/tools/gitlab-projects-settings/gitlab-projects-settings:test-latest
  before_script:
    - !reference [.unit-tests-template, before_script]
    - !reference ['.test:template', before_script]

quality:coverage:
  needs: