check version definition:
  stage: qa
  extends:
  - .rules:merge_request_pipelines
  needs: []
  script:
  - grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' VERSION

check modules:
  stage: qa
  extends:
  - .rules:merge_request_pipelines:no_docs
  - .no_cache_and_dependencies
  needs:
  - 'prepare done'
  script:
  - make check_modules

check generated files:
  stage: qa
  extends:
  - .rules:merge_request_pipelines:no_docs
  - .no_cache_and_dependencies
  needs:
  - 'prepare done'
  script:
  - make check_generated_files

check magefiles:
  stage: qa
  extends:
    - .rules:merge_request_pipelines:no_docs
    - .no_cache_and_dependencies
  needs:
    - 'prepare done'
  script:
    - make check_magefiles

check test directives:
  stage: qa
  extends:
  - .rules:merge_request_pipelines:no_docs
  - .no_cache_and_dependencies
  needs:
  - 'prepare done'
  script:
  - make check_test_directives

code_quality:
  stage: qa
  extends:
  - .rules:merge_request_pipelines:no_docs
  - .no_dependencies
  # Use GOCACHE instead of GOLANGCI_LINT_CACHE
  # to avoid [false lint positives](https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/2187#note_373008672)
  - .go-cache
  image: registry.gitlab.com/gitlab-org/ci-cd/runner-tools/runner-linters:1.62.0-go1.23.3
  needs: []
  allow_failure: true
  variables:
    REPORT_FILE: gl-code-quality-report.json
    LINT_FLAGS: "--color never --timeout 15m"
    OUT_FORMAT: code-climate
    GOLANGLINT_VERSION: "" # Don't add version suffix to Makefile's GOLANGLINT (use plain golangci-lint from image)
  before_script:
  - !reference [.go-cache, before_script]
  # Ensure the goargs linter plugin is available at .tmp/goargs.so to suit .golangci.yml
  - mkdir .tmp && ln -s /usr/lib/goargs.so .tmp/goargs.so
  # Copy the Docker image's golangci-lint to the location expected by `make lint` so that it is not built
  - cp $(which golangci-lint) .tmp/golangci-lint
  script:
  # Write the code coverage report to gl-code-quality-report.json
  # and print linting issues to stdout in the format: path/to/file:line description
  - make --silent lint | tee ${REPORT_FILE}
  timeout: 15 minutes
  artifacts:
    reports:
      codequality: ${REPORT_FILE}
    paths:
    - ${REPORT_FILE}
    when: always
    expire_in: 7d

mage tests:
    extends:
    - .rules:merge_request_pipelines:no_docs
    stage: qa
    needs:
    - 'prepare done'
    script:
    - make mage-test

# Perform documentation linting and link checking on Markdown files
docs:lint markdown:
  image: registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.20-vale-3.7.1-markdownlint2-0.14.0-lychee-0.15.1
  stage: qa
  extends:
  - .rules:merge_request_pipelines
  - .no_cache_and_dependencies
  needs: []
  script:
  # Lint content and Markdown, and check links
  - make lint-docs VALE_MIN_ALERT_LEVEL=error

docs:check feature flags:
  stage: qa
  extends:
  - .rules:merge_request_pipelines
  - .no_cache_and_dependencies
  script:
  - cp docs/configuration/feature-flags.md docs/configuration/feature-flags.md.orig
  - make update_feature_flags_docs
  - |
    diff docs/configuration/feature-flags.md.orig docs/configuration/feature-flags.md || (
      echo
      echo "Feature Flags list in documentation is not up-to-date"
      echo "Run 'make update_feature_flags_docs' to update it"
      echo
      exit 1
    )

docs:check development docs Go version:
  extends:
  - .rules:merge_request_pipelines
  - .no_cache_and_dependencies
  stage: qa
  script:
    - export GO_VERSION=$(cat .gitlab/ci/_common.gitlab-ci.yml | yq '.variables.GO_VERSION')
    - export EXIT_CODE=0
    - grep $GO_VERSION docs/development/index.md || EXIT_CODE=$?
    - if [ $EXIT_CODE -ne 0 ]; then echo "Make sure to update all Go versions in docs/development/index.md to $GO_VERSION"; exit 1; fi

docs:check Kubernetes API docs:
  extends:
  - .rules:merge_request_pipelines
  - .no_cache_and_dependencies
  stage: qa
  script:
    - cp docs/executors/kubernetes/index.md docs/executors/kubernetes/index.md.orig
    - mage k8s:generatePermissionsDocs
    - |
        diff docs/executors/kubernetes/index.md.orig docs/executors/kubernetes/index.md || (
          echo
          echo "Kubernetes API list in documentation is not up-to-date"
          echo "Run 'mage k8s:generatePermissionsDocs' to update it"
          echo
          exit 1
        )
 