name: Python package

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  lint:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.12']
    steps:
    - name: Check out the code
      uses: actions/checkout@v3
    - name: Install rye
      uses: eifinger/setup-rye@v4
    - name: Pin Python version
      run: rye pin ${{ matrix.python-version }}
    - name: Sync dependencies
      run: rye sync
    - name: Lint check
      run: rye check
    - name: Check formatting
      run: rye format --check

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        settings:
        - python: '3.9'
          coverage: false
        - python: '3.10'
          coverage: false
        - python: '3.11'
          coverage: false
        - python: '3.12'
          coverage: true
    steps:
    - name: Check out the code
      uses: actions/checkout@v3
    - name: Install rye
      uses: eifinger/setup-rye@v4
    - name: Pin Python version
      run: rye pin ${{ matrix.settings.python }}
    - name: Sync dependencies
      run: rye sync
    - name: Test with pytest
      if: ${{ !matrix.settings.coverage }}
      run: rye run pytest
    - name: Test with pytest and coverage
      if: ${{ matrix.settings.coverage }}
      run: rye run pytest --cov=src --cov-report term-missing
    - name: Verify coverage
      if: ${{ matrix.settings.coverage }}
      run: rye run coverage report | tail -1 | egrep "TOTAL +[0-9]+ +0 +100%"
