name: Release package

on:
    push:
        tags:
            - 'v*'

jobs:
  build-test:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: |
          set -ex
          curl -sSL https://install.python-poetry.org | POETRY_HOME=$HOME/.poetry python3 - --yes
          $HOME/.poetry/bin/poetry install

      - name: Build and publish to PyPI
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine build
          python -m build
          python -m twine upload dist/*
