Publish to PyPI #15
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: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: release | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Verify tag matches package version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" | |
| PACKAGE_VERSION="$(python -c \"import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])\")" | |
| if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then | |
| echo "Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)." | |
| exit 1 | |
| fi | |
| - name: Build distributions | |
| run: | | |
| python -m pip install -U pip build | |
| python -m build | |
| - name: Publish to PyPI | |
| env: | |
| PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| if [ -z "$PYPI_API_TOKEN" ]; then | |
| echo "Missing PYPI_API_TOKEN secret." | |
| exit 1 | |
| fi | |
| python -m pip install -U twine | |
| python -m twine upload -u __token__ -p "$PYPI_API_TOKEN" dist/* |