name: Release

on:
  release:
    types:
      - published

permissions: {}

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build package
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4.2.2

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

      - name: Install uv
        uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc  # v6.4.3
        with:
          version: "0.7.19"

      - name: Set version number
        run: script/set-version ${{ github.event.release.tag_name }}

      - name: Build
        run: uv build

      - name: Upload dists
        uses: actions/upload-artifact@v4.6.2
        with:
          name: "dist"
          path: "dist/"
          if-no-files-found: error
          retention-days: 5

  publish:
    name: Publish release to PyPI
    runs-on: ubuntu-latest
    needs: "build"
    environment:
      name: release
      url: https://pypi.org/project/awesomeversion
    permissions:
      id-token: write
    steps:
    - name: Download dists
      uses: actions/download-artifact@v4.3.0
      with:
        name: "dist"
        path: "dist/"

    - name: Publish dists to PyPI
      uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4