name: CI

on:
  push:
    branches: [ main ]
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: ["3.10"]

    steps:
    - name: Block DNP PRs
      if: startsWith(github.event.pull_request.title, 'DNP')
      run: |
        echo "Title starts with DNP. Blocking CI."
        echo "Title: {% raw %}${{ github.event.pull_request.title }}{% endraw %}"
        exit 1

    - uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: {% raw %}${{ matrix.python-version }}{% endraw %}

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install .[dev]

    - name: Lint
      run: flake8 src/

    - name: Format check
      run: black --check src/

    - name: Type check
      run: mypy src/

    - name: Run tests
      run: |
        if [ ! -d "tests" ]; then
          echo "No tests directory found. Skipping tests."
          exit 0
        fi
        pytest tests/ || if [ $? -eq 5 ]; then exit 0; else exit $?; fi

