# This workflow will build a Python Package using Hatch and upload it to PyPi when a release is published
# No action on a release still in draft
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# and: https://github.com/pypa/hatch/issues/669 and https://github.com/marketplace/actions/pypi-publish

name: Publish via Hatch

on:
  release:
    types: [published]

permissions:
  contents: read

jobs:
  build-dist:
    name: Build release to /dist
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install hatch and Update Dependencies
        run: |
          pipx install hatch
          pipx inject hatch virtualenv --upgrade

      - name: Verify Hatch Environment Compatibility
        run: hatch env show

      - name: Build dist
        run: hatch build

      - name: Upload dist
        uses: actions/upload-artifact@v6
        with:
          name: dist
          path: dist/

  pypi-publish:
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    needs: build-dist
    environment:
      name: pypi
      url: https://pypi.org/project/ramses_rf
    steps:
      - name: Download dist
        uses: actions/download-artifact@v7
        with:
          name: dist
          path: dist/
      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.RF_PYPI_API_TOKEN }}
      - run: echo "🍏 This job's status is ${{ job.status }}."
