name: Create release

on:
  push:
    tags:
    - "v*"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

env:
  FORCE_COLOR: "1"
  UV_SYSTEM_PYTHON: "1"  # make uv do global installs

jobs:
  publish-pypi:
    runs-on: ubuntu-latest
    name: PyPI Release
    environment: release
    if: github.repository_owner == 'breathe-doc'
    permissions:
      id-token: write  # for PyPI trusted publishing
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3"

      - name: Install uv
        uses: astral-sh/setup-uv@v6
        with:
          version: latest
          enable-cache: false

      - name: Install Ruff
        uses: astral-sh/ruff-action@v3
        with:
          args: --version
          version: 0.9.2

      - name: Install build dependencies (pypa/build, twine)
        # Install jinja2 to make the parser - probably better to install it via
        # the Sphinx dependency in the pyproject.toml file but I don't know how
        # to do that at the moment
        run: uv pip install build "twine>=5.1" "jinja2>=3.1.6" setuptools

      - name: Generate parser
        run: |
          make parser
          make format-parser

      - name: Build distribution
        run: python -m build

      - name: Check distribution
        run: |
          twine check --strict dist/*

      - name: Upload to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
