# If you change this name also do it in tests.yml and ci_metrics.yml
name: Tests

on:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - ready_for_review
    paths-ignore:
      # we skip the tests unless the code changes. The problem is that GitHub will run the check anyway if any other
      # file outside the code changed (e.g. the release notes). Hence, we need a second filter down below.
      # keep the list in sync with the paths defined in the `tests.yml` workflow and below in this file
      - "haystack/**/*.py"
      - "haystack/core/pipeline/predefined/*"
      - "test/**/*.py"
      - "pyproject.toml"
      - ".github/utils/*.py"

jobs:
  check_if_changed:
    name: Check if changed
    runs-on: ubuntu-slim
    permissions:
      pull-requests: read
    outputs:
      code_changes: ${{ steps.changes.outputs.code_changes }}
    steps:
      - uses: actions/checkout@v6
      - name: Check for changed code
        id: changes
        uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
        with:
          # keep the list in sync with the paths defined in the `tests.yml` workflow and above in this file
          filters: |
            code_changes:
              - "haystack/**/*.py"
              - "haystack/core/pipeline/predefined/*"
              - "test/**/*.py"
              - "pyproject.toml"
              - ".github/utils/*.py"

  trigger-catch-all:
    name: Tests completed
    # Don't run this check if the PR contains both code and non-code changes (e.g. release notes)
    needs: check_if_changed
    if: needs.check_if_changed.outputs.code_changes == 'false'
    uses: ./.github/workflows/tests_skipper_workflow.yml
    with:
      tests_were_skipped: true
