Deploy to PyPI #5
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: Deploy to PyPI | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Release"] | |
| types: | |
| - completed | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to deploy (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| workflow_call: | |
| inputs: | |
| version: | |
| description: 'Version to deploy (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| deploy_pypi: | |
| name: Deploy to PyPI | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| - name: Extract version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| VERSION="${{ inputs.version }}" | |
| else | |
| VERSION=$(git describe --tags --abbrev=0) | |
| fi | |
| VERSION=$(echo "$VERSION" | sed 's/^v//') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Deploying version: $VERSION" | |
| - name: Update version in pyproject.toml | |
| run: | | |
| VERSION="${{ steps.get_version.outputs.version }}" | |
| sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Check distribution | |
| run: twine check dist/* | |
| - name: Publish to Test PyPI (optional) | |
| if: github.event_name == 'workflow_dispatch' | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }} | |
| run: | | |
| twine upload --repository testpypi dist/* --skip-existing || true | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| run: | | |
| twine upload dist/* |