name: CI

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
          cache: "pip"
      - run: pip install ruff
      - run: ruff check centurion/ tests/
      - run: ruff format --check centurion/ tests/

  typecheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
          cache: "pip"
      - run: pip install .[dev] mypy
      - run: mypy centurion/

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.12", "3.13"]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: "pip"
      - run: pip install .[dev]
      - run: pytest tests/ -v --cov=centurion --cov-report=xml:coverage.xml
      - uses: actions/upload-artifact@v4
        if: matrix.python-version == '3.13'
        with:
          name: coverage-report
          path: coverage.xml
          retention-days: 7

  coverage:
    runs-on: ubuntu-latest
    needs: test
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
          cache: "pip"
      - uses: actions/download-artifact@v4
        with:
          name: coverage-report
      - run: pip install diff-cover
      - run: diff-cover coverage.xml --compare-branch=origin/main --fail-under=90

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
          cache: "pip"
      - run: pip install build
      - run: python -m build
      - run: pip install dist/*.whl
      - run: centurion --help
