Publish to PyPI #1
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: | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: "Release tag to publish, for example v0.1.1" | |
| required: true | |
| jobs: | |
| build: | |
| name: Build distributions | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Validate release ref | |
| run: | | |
| case "${{ inputs.ref }}" in | |
| v*) ;; | |
| *) echo "PyPI publishes must use a PEP 440-compatible v* release tag."; exit 1 ;; | |
| esac | |
| - name: Checkout release tag | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ inputs.ref }} | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Install build tools | |
| run: python -m pip install --upgrade build twine | |
| - name: Build wheel and sdist | |
| run: python -m build | |
| - name: Twine check | |
| run: python -m twine check dist/* | |
| - name: Upload distributions | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: python-distributions | |
| path: dist/* | |
| if-no-files-found: error | |
| publish: | |
| name: Publish distributions | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Download distributions | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: python-distributions | |
| path: dist | |
| - name: Publish package distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 |