name: 01. Pull Request Checks

on:
  workflow_dispatch:
  pull_request:
    branches: [ main, develop ]
    paths-ignore:
      - 'docs/**'
      - '**.md'
      - 'LICENSE'
      - 'CONTRIBUTING.md'
      - '**.png'
      - '**.jpg'
      - '**.jpeg'
      - '**.gif'
      - '**.svg'
      - '.gitignore'
      - '.editorconfig'

jobs:
  lint:
    uses: ./.github/workflows/_lint.yml

  test-lite:
    uses: ./.github/workflows/_test_lite.yml
    with:
      os_json: '["ubuntu-24.04"]'
      python_json: '["3.10"]'

  check-deps:
    runs-on: ubuntu-24.04
    outputs:
      deps_changed: ${{ steps.check.outputs.deps_changed }}
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Check for dependency changes
        id: check
        run: |
          git fetch origin ${{ github.base_ref }}
          
          # Define grep pattern for dependency files
          PATTERN="pyproject\.toml|setup\.py|uv\.lock|src/CMakeLists\.txt|third_party/|\.github/workflows/_build\.yml"
          
          # Check for changes
          CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E "$PATTERN" || true)
          
          if [ -n "$CHANGED_FILES" ]; then
            echo "Dependency changes detected:"
            echo "$CHANGED_FILES"
            echo "deps_changed=true" >> $GITHUB_OUTPUT
          else
            echo "No dependency changes detected."
            echo "deps_changed=false" >> $GITHUB_OUTPUT
          fi

  build:
    needs: check-deps
    if: ${{ needs.check-deps.outputs.deps_changed == 'true' }}
    uses: ./.github/workflows/_build.yml
