name: uv-publish
on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  build-and-publish:
    name: Build and Publish to PyPI
    if: github.repository == 'letta-ai/letta'  # TODO: if the repo org ever changes, this must be updated
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repository
        uses: actions/checkout@v4

      - name: Set up python 3.12
        id: setup-python
        uses: actions/setup-python@v5
        with:
          python-version: 3.12

      - name: Install uv
        run: |
          curl -LsSf https://astral.sh/uv/install.sh | sh
          echo "$HOME/.cargo/bin" >> $GITHUB_PATH

      - name: Build the Python package
        run: uv build

      - name: Publish the package to PyPI
        env:
          UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
        run: uv publish
