name: Deploy to Pypi

on:
  release:
    types:
      - published
  workflow_dispatch:

jobs:
  pypi-publish:
    name: Publish release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: pypi
      url: https://pypi.org/p/torch-harmonics

    steps:
      - uses: actions/checkout@v4

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

      - name: Install build dependencies
        run: |
          python3 -m pip install --upgrade pip setuptools build wheel
          python3 -m pip install numpy
          python3 -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu

      - name: Build distribution
        run: |
          python3 -m build --sdist

      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          user: __token__
          password: ${{ secrets.PYPI_PASSWORD }}