# PyPI Publish Workflow - GitHub Actions
# Generated by pypreset augment

name: Publish to PyPI

on:
  push:
    tags:
      - "v*"

permissions:
  id-token: write
  contents: read

jobs:
  publish:
    runs-on: ubuntu-latest

    environment:
      name: pypi
      url: {% raw %}https://pypi.org/p/${{ github.event.repository.name }}{% endraw %}

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python {{ project.python_version }}
        uses: actions/setup-python@v5
        with:
          python-version: "{{ project.python_version }}"

{% if package_manager == "poetry" %}
      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true

      - name: Install dependencies
        run: poetry install --no-interaction

{% if testing.enabled %}
{% if testing.framework == "pytest" %}
      - name: Run tests
        run: poetry run pytest -v
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: poetry run python -m unittest discover -s tests -v
{% endif %}
{% endif %}

      - name: Build package
        run: poetry build

{% elif package_manager == "uv" %}
      - name: Install uv
        uses: astral-sh/setup-uv@v4

      - name: Install dependencies
        run: uv sync

{% if testing.enabled %}
{% if testing.framework == "pytest" %}
      - name: Run tests
        run: uv run pytest -v
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: uv run python -m unittest discover -s tests -v
{% endif %}
{% endif %}

      - name: Build package
        run: uv build

{% elif package_manager == "pdm" %}
      - name: Install PDM
        uses: pdm-project/setup-pdm@v4
        with:
          python-version: "{{ project.python_version }}"

      - name: Install dependencies
        run: pdm install

{% if testing.enabled %}
{% if testing.framework == "pytest" %}
      - name: Run tests
        run: pdm run pytest -v
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: pdm run python -m unittest discover -s tests -v
{% endif %}
{% endif %}

      - name: Build package
        run: pdm build

{% elif package_manager == "hatch" %}
      - name: Install Hatch
        run: pip install hatch

{% if testing.enabled %}
{% if testing.framework == "pytest" %}
      - name: Run tests
        run: hatch run test
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: hatch run python -m unittest discover -s tests -v
{% endif %}
{% endif %}

      - name: Build package
        run: hatch build

{% else %}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install build
          pip install -e ".[dev]"

{% if testing.enabled %}
{% if testing.framework == "pytest" %}
      - name: Run tests
        run: pytest -v
{% elif testing.framework == "unittest" %}
      - name: Run tests
        run: python -m unittest discover -s tests -v
{% endif %}
{% endif %}

      - name: Build package
        run: python -m build

{% endif %}
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
