name: BMAD Gates

on:
  pull_request:
  push:
    branches: [ main ]

jobs:
  story-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Ensure worktrees exists
        run: |
          test -d worktrees
          ls -la worktrees
      - name: Run story lint
        run: |
          python bmad_story_lint.py worktrees/

  code-complexity:
    runs-on: ubuntu-latest
    needs: story-lint
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Run code complexity gate
        run: |
          python bmad_code_complexity_gate.py .

  quality-gates:
    runs-on: ubuntu-latest
    needs: code-complexity
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install -r requirements.txt
          python -m pip install coverage==7.5.4 ruff==0.4.10 mypy==1.10.0
      - name: Run coverage gate
        run: |
          python -m coverage run -m unittest discover -s tests -p "test_*.py"
          python -m coverage report --fail-under=80
      - name: Run mypy
        run: |
          python -m mypy src
      - name: Run ruff check
        run: |
          python -m ruff check .
      - name: Run ruff format check
        run: |
          python -m ruff format --check .
