Commit 0b032f37 authored by Adrian DC's avatar Adrian DC
Browse files

ci(gitlab-ci): create 'commits' job to validate with 'commitizen'

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 27c49f89
Loading
Loading
Loading
Loading
+60 −0
Changes for .gitlab-ci.yml: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -473,6 +473,64 @@ codestyle:
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      when: on_success

commits:
  stage: prepare
  image: registry.gitlab.com/radiandevcore/tools/gcil/gcil:codestyle
  needs: []
  before_script:
    # Check system context
    - git cz version -r
    # Show commits documentation
    - |
      (
        set +x
        echo ' '
        for hint in 'example:33' 'info:36' 'schema:32'; do
          command="${hint%%:*}"
          color="${hint##*:}"
          echo '---'
          echo "git cz ${command}:"
          echo -e "\033[1;${color}m"
          git cz "${command}" | sed 's#^$# #g'
          echo -e '\033[0m '
        done
        echo '---'
      )
  script:
    # Detect commits range
    - remote=$(git remote -v | grep '(fetch)' | awk '{print $1}' | head -n1)
    - |
      if [ ! -z "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-}" ]; then
        base_sha=$(git rev-parse "${remote}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}")
        base_branch=$(git rev-parse --abbrev-ref "${remote}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}")
      elif [ ! -z "${CI_DEFAULT_BRANCH:-}" ]; then
        base_sha=$(git rev-parse "${remote}/${CI_DEFAULT_BRANCH}")
        base_branch=$(git rev-parse --abbrev-ref "${remote}/${CI_DEFAULT_BRANCH}")
      else
        base_sha=$(git rev-parse "${remote}/HEAD")
        base_branch=$(git rev-parse --abbrev-ref "${remote}/HEAD")
      fi
    - head_sha="${CI_COMMIT_SHA:-HEAD}"
    - |
      none_sha='0000000000000000000000000000000000000000'
      before_sha="${CI_COMMIT_BEFORE_SHA:-${none_sha}}"
      if [ "${base_sha}" = "${head_sha}" ] && [ ! "${before_sha}" = "${none_sha}" ] && git cat-file -e "${before_sha}" 2>/dev/null; then
        base_sha="${before_sha}"
      fi
    # Validate commits range
    - |
      set +x
      echo ' '
      echo '---'
      echo -e "\033[0m\033[1mINFO: Commitizen checks from \033[1;33m'${base_branch}' \033[0m\033[1m(\033[1;36m${base_sha}\033[0m\033[1m) to \033[1;36m'${head_sha}'\033[0m"
      echo ' '
      git log --pretty=oneline --abbrev-commit "${base_sha}^..${head_sha}" | sed "s#^\([^ ]*\) #$(printf '\033[1;33m')\1$(printf '\033[0m') #g"
      echo ' '
      set -x
      git cz check --rev-range "${base_sha}^..${head_sha}"
  rules:
    - when: on_success

lint:
  stage: prepare
  image: registry.gitlab.com/radiandevcore/tools/gcil/gcil:codestyle
@@ -528,6 +586,8 @@ build:
  needs:
    - job: codestyle
      artifacts: false
    - job: commits
      artifacts: false
    - job: lint
      artifacts: false
    # - job: typings
+1 −0
Changes for requirements/quality.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
git+https://github.com/AdrianDC/commitizen.git@prerelease # == 3.29.0.AdrianDC.20240813
mypy>=0.971
pylint>=2.6.0
types-PyYAML>=6.0.12.2