# 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: blacksmith-4vcpu-ubuntu-2204
    # Run when manually dispatched for "app server" OR for tag pushes that don't contain '-cli'
    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'))
    steps:
      - uses: actions/checkout@v4
      - uses: useblacksmith/setup-python@v6
        with:
          python-version: 3.12
      - name: Install Poetry
        uses: snok/install-poetry@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
        run: poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }}
