# Publishes the OpenHands PyPi package
name: Publish PyPi Package

on:
  workflow_dispatch:
    inputs:
      reason:
        description: "What are you publishing?"
        required: true
        type: choice
        options:
          - app server
        default: app server
  push:
    tags:
      - "*"

jobs:
  release:
    runs-on: ubuntu-22.04
    # Run when manually dispatched for "app server" OR for tag pushes that don't contain '-cli' and don't start with 'cloud-'
    if: |
      (github.event_name == 'workflow_dispatch' && github.event.inputs.reason == 'app server')
      || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-cli') && !startsWith(github.ref, 'refs/tags/cloud-'))
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: 3.12
      - name: Install Poetry
        uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
        with:
          virtualenvs-in-project: true
          virtualenvs-path: ~/.virtualenvs
      - name: Install Poetry Dependencies
        run: poetry install --no-interaction --no-root
      - name: Build poetry project
        run: ./build.sh
      - name: publish
        env:
          PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
        run: poetry publish -u __token__ -p "$PYPI_TOKEN"
