Publish to PyPI #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to PyPI | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| deploy_to_test_pypi: | |
| description: 'Deploy to Test PyPI instead of production' | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: python/ai-server | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine wheel setuptools | |
| - name: Install package dependencies | |
| run: | | |
| pip install -e . | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Check distribution | |
| run: | | |
| twine check dist/* | |
| - name: Publish to Test PyPI (manual trigger with test option) | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_test_pypi == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| repository-url: https://test.pypi.org/legacy/ | |
| packages-dir: python/ai-server/dist/ | |
| - name: Verify Test PyPI installation (manual trigger with test option) | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_test_pypi == 'true' | |
| run: | | |
| sleep 60 # Wait for package to be available | |
| pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ai-server-sdk | |
| python -c "import ai_server; print('Package imported successfully')" | |
| - name: Publish to PyPI (on release) | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| packages-dir: python/ai-server/dist/ | |
| - name: Publish to Test PyPI (manual trigger without test option) | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_to_test_pypi != 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| packages-dir: python/ai-server/dist/ |