name: CI/CD

on: [push, pull_request]

jobs:
  tests:
    name: "Python ${{ matrix.python-version }} ${{ matrix.os }}"
    runs-on: "${{ matrix.os }}"
    strategy:
      matrix:
        python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
        os: [ubuntu-latest, windows-latest, macos-13]
    steps:
      - uses: actions/checkout@v4
      - uses: pdm-project/setup-pdm@v4
        name: Setup Python and PDM
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64
          version: 2.20.1
      - name: Install dependencies
        run: |
          pdm sync -v -dG dev -dG test --no-self

      - name: Tests
        run: pdm run pytest tests -o log_cli=true -o log_cli_level=DEBUG
        env:
          PYTHONASYNCIODEBUG: 1

  publish:
    needs: tests
    if: startsWith(github.ref, 'refs/tags/')

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: pdm-project/setup-pdm@v4
        name: Setup Python and PDM
        with:
          python-version: "3.10"
          architecture: x64
          version: 2.20.1

      - name: Publish
        run: |
          pdm publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }}
