name: Publish Python SDK on: push: branches: - main paths: - 'sdks/python/pyproject.toml' workflow_dispatch: jobs: publish: name: Publish to PyPI runs-on: ubuntu-latest defaults: run: working-directory: sdks/python steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v6 with: python-version: '3.12' - name: Install uv uses: astral-sh/setup-uv@v4 - name: Extract version from pyproject.toml id: version run: | VERSION=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml) echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Check if version already published id: check run: | HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://pypi.org/pypi/openrag-sdk/${{ steps.version.outputs.version }}/json) if [ "$HTTP_STATUS" = "200" ]; then echo "exists=true" >> $GITHUB_OUTPUT else echo "exists=false" >> $GITHUB_OUTPUT fi - name: Build package if: steps.check.outputs.exists == 'false' run: uv build - name: Publish to PyPI if: steps.check.outputs.exists == 'false' run: uv publish env: UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }} - name: Skip publish (version exists) if: steps.check.outputs.exists == 'true' run: echo "Version ${{ steps.version.outputs.version }} already exists on PyPI, skipping publish"