Publish Python SDK to PyPI #21
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 Python SDK to PyPI | |
| on: | |
| release: | |
| types: [created] | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment' | |
| required: true | |
| default: 'test' | |
| type: choice | |
| options: | |
| - test | |
| - prod | |
| jobs: | |
| publish-testpypi: | |
| if: github.event.inputs.environment == 'test' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'test') | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: testpypi | |
| url: https://test.pypi.org/projects/a3m-router | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install build twine | |
| - name: Build package | |
| run: | | |
| cd python | |
| python -m build | |
| - name: Publish to Test PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }} | |
| run: | | |
| cd python | |
| python -m twine upload --repository testpypi dist/* | |
| publish-pypi: | |
| if: github.event.inputs.environment == 'prod' || github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/projects/a3m-router | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install build twine | |
| - name: Build package | |
| run: | | |
| cd python | |
| python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| run: | | |
| cd python | |
| python -m twine upload --verbose dist/* | |
| test-package: | |
| runs-on: ubuntu-latest | |
| needs: publish-testpypi | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install from Test PyPI | |
| env: | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }} | |
| run: | | |
| pip install --index-url https://test.pypi.org/simple/ a3m-router | |
| - name: Test import | |
| run: | | |
| python -c "from a3m import A3MRouter, __version__; print(f'A3M Router SDK v{__version__} installed successfully!')" |