---
name: Release

# yamllint disable-line rule:truthy
on:
  release:
    types:
      - published

env:
  DEFAULT_PYTHON: "3.13"

jobs:
  release:
    name: Releasing to PyPi
    runs-on: ubuntu-latest
    environment:
      name: release
      url: https://pypi.org/p/pypaperless
    permissions:
      contents: write
      id-token: write # important for trusted publishing (pypi)
    steps:
      - name: ⤵️ Check out code from GitHub
        uses: actions/checkout@v4.2.2
      - name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
        id: python
        uses: actions/setup-python@v5.6.0
        with:
          python-version: ${{ env.DEFAULT_PYTHON }}
      - name: 🏗 Set up uv
        run: |
          pipx install uv
          uv venv
      - name: 🏗 Install Python dependencies
        run: uv sync --group dev
      - name: 🏗 Set package version
        run: |
          version="${{ github.event.release.tag_name }}"
          version="${version,,}"
          version="${version#v}"
          sed -i "s/^version = .*/version = \"${version}\"/" pyproject.toml
      - name: 🏗 Build package
        run: uv build
      - name: 🚀 Publish to PyPi
        uses: pypa/gh-action-pypi-publish@v1.12.4
        with:
          verbose: true
          print-hash: true
      - name: ✍️ Sign published artifacts
        uses: sigstore/gh-action-sigstore-python@v3.0.1
        with:
          inputs: ./dist/*.tar.gz ./dist/*.whl
          release-signing-artifacts: true
