.pre_check_template:
  stage: pre_check
  image: python:3.9
  tags: ["build", "amd64", "internet"]
  dependencies: []

check_copyright:
  extends:
    - .pre_check_template
  allow_failure: false
  before_script:
    - pip install git+https://github.com/espressif/check-copyright.git@v1.0.3
  script:
    - python -m check_copyright --verbose --dry-run --ignore tools/ci/check_copyright_ignore.txt --config tools/ci/check_copyright_config.yaml .

check_example_paths:
  extends:
    - .pre_check_template
    - .rules:pre_check:components
  script:
    - pip install --upgrade pip
    - pip install pyyaml
    - python ${CI_PROJECT_DIR}/tools/ci/check_components.py

check_pre_commit:
  extends:
    - .pre_check_template
  before_script:
    - pip install pre-commit
  script:
    - |
      # merged results pipelines, by default
      if [[ -n $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA ]]; then
        MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA)
      # merge request pipelines, when the mr got conflicts
      elif [[ -n $CI_MERGE_REQUEST_DIFF_BASE_SHA ]]; then
        MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA)
      # other pipelines, like the protected branches pipelines
      else
        MODIFIED_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
      fi
      # print the MODIFIED_FILES
      echo "MODIFIED_FILES: $MODIFIED_FILES"
    - pre-commit install --allow-missing-config -t pre-commit -t commit-msg
    - export SKIP=check-copyright # copyrights has been checked in separate job
    - pre-commit run --files $MODIFIED_FILES

check_readme_links:
  extends:
    - .pre_check_template
    - .rules:pre_check:readme
  allow_failure: true
  script:
    - python ${CI_PROJECT_DIR}/tools/ci/check_readme_links.py
