name: CI
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
permissions:
contents: read
jobs:
test:
name: Test Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -e .[dev]
- name: Run tests with pytest
run: |
pytest tests/ -v --cov=src --cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.12'
with:
file: ./coverage.xml
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint and Format Check
runs-on: ubuntu-latest
continue-on-error: true # Don't block PR merges on linting issues
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black isort
- name: Run flake8
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 src/ --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 src/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check formatting with black
continue-on-error: true
run: |
black --check src/ tests/ || echo "⚠️ Code formatting issues detected. Run 'black src/ tests/' to fix."
- name: Check import sorting with isort
continue-on-error: true
run: |
isort --check-only --profile black src/ tests/ || echo "⚠️ Import sorting issues detected. Run 'isort --profile black src/ tests/' to fix."
# Summary job for branch protection
ci-success:
name: CI Success
runs-on: ubuntu-latest
needs: [test, lint]
if: always()
steps:
- name: Check test results
run: |
if [[ "${{ needs.test.result }}" != "success" ]]; then
echo "Tests failed"
exit 1
fi
echo "All required checks passed"