workflow:
  rules:
    # don't run a pipeline for a issue branch that does not have a merge request
    - if: '$CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME =~ /^[0-9]+-/'
      when: never
    # skip branch pipeline if the commit starts with release
    # the release job will create a commit for each new release. This commit should not be handled by the ci!
    - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_MESSAGE =~ /^release:/'
      when: never
    # if the current branch is not protected or renovate branch and a merge request for this branch exists
    # skip the pipeline
    - if: '$CI_COMMIT_REF_PROTECTED != "true" && $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_COMMIT_BRANCH !~ /^renovate\//'
      when: never
      # do not run merge request pipelines if the source branch is the default branch
    - if: "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == $CI_DEFAULT_BRANCH"
      when: never
    # ensures that the release build for docker containers have the latest tag if the version is not a digest version
    - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
      variables:
        LATEST: "true"
    - when: always

variables:
  NODE_VERSION: "20.11.0"

include:
  - local: .gitlab/ci/utilities/nx.yaml
  - local: .gitlab/ci/utilities/npm-cache.yaml
  - local: .gitlab/ci/jobs/setup.yaml
  - local: .gitlab/ci/jobs/pages.yaml
    rules:
      # do not run for merge train merge requests
      - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'
        when: never
      # do not run for merge request that target the renovate branch
      - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^renovate\// || $CI_COMMIT_BRANCH =~ /^renovate\//'
        when: never
        # do not run for merge requests that target the snyk branch
      - if: "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^snyk-/ || $CI_COMMIT_BRANCH =~ /^snyk-/"
        when: never
      - when: always
  - local: .gitlab/ci/jobs/coverage-report.yaml
    rules:
      # do not run for merge train merge requests
      - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'
        when: never
      # do not run for merge request that target the renovate branch
      - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^renovate\// || $CI_COMMIT_BRANCH =~ /^renovate\//'
        when: never
        # do not run for merge requests that target the snyk branch
      - if: "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^snyk-/ || $CI_COMMIT_BRANCH =~ /^snyk-/"
        when: never
      - when: always

  # include the pipeline for merge requests
  - local: .gitlab/ci/review.yaml
    rules:
      # only run for merge requests
      - if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
        when: never
        # do not run for merge train merge requests
      - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'
        when: never
        # do not run for merge request that target the renovate branch
      - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^renovate\// || $CI_COMMIT_BRANCH =~ /^renovate\//'
        when: never
        # do not run for merge requests that target the snyk branch
      - if: "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^snyk-/ || $CI_COMMIT_BRANCH =~ /^snyk-/"
        when: never
        # run for all other merge request types
      - if: "$CI_MERGE_REQUEST_EVENT_TYPE =~ /^merged_result|detached$/"

  # include the pipeline for merge train
  - local: .gitlab/ci/merge-train.yaml
    rules:
      - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'

  # include the pipeline for renovate branches
  - local: .gitlab/ci/renovate.yaml
    rules:
      - if: '$CI_COMMIT_BRANCH =~ /^renovate\//'

  # include the pipeline for snyk branches
  - local: .gitlab/ci/snyk.yaml
    rules:
      - if: "$CI_COMMIT_BRANCH =~ /^snyk-/"

  # include the pipeline for normal branches
  - local: .gitlab/ci/branch.yaml
    rules:
        # do not run for renovate branches
      - if: '$CI_COMMIT_BRANCH =~ /^renovate\//'
        when: never
        # do not run for snyk branches
      - if: "$CI_COMMIT_BRANCH =~ /^snyk-/"
        when: never
        # do not run for issue branches
      - if: "$CI_COMMIT_BRANCH =~ /^[0-9]+-/"
        when: never
        # do not run for tags
      - if: "$CI_COMMIT_TAG"
        when: never
        # do not run for the default branch
      - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
        when: never
        # do not run if a merge request for this branch exists
      - if: "$CI_OPEN_MERGE_REQUESTS"
        when: never
      - if: "$CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE =~ /push|web/"

  # include the pipeline for the default branch
  - local: .gitlab/ci/default.yaml
    rules:
      - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"

  # include the pipeline for release tags
  - local: .gitlab/ci/release.yaml
    rules:
      - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/'
