name: Release

on:
  workflow_dispatch:
  release:
    types:
      - created

jobs:
  release:
    name: release
    runs-on: ubuntu-latest
    if: ${{ github.repository }} == 'stac-utils/stac-pydantic'
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Install uv
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
        with:
          version: "0.9.*"
          enable-cache: true
          python-version: '3.14'

      - name: Install dependencies
        run: |
          uv sync --group deploy

      - name: Set tag version
        id: tag
        run: |
          echo "version=${GITHUB_REF#refs/*/}"
          echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

      - name: Set module version
        id: module
        run: |
          echo "version=$(uv run hatch --quiet version)" >> $GITHUB_OUTPUT

      - name: Build and publish
        if: ${{ steps.tag.outputs.version }} == ${{ steps.module.outputs.version}}
        env:
          HATCH_INDEX_USER: ${{ secrets.PYPI_STACUTILS_USERNAME }}
          HATCH_INDEX_AUTH: ${{ secrets.PYPI_STACUTILS_PASSWORD }}
        run: |
          uv run hatch build
          uv run hatch publish
