Tests in CI, badges, deploy only when tests pass #2
Workflow file for this run
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
| # Publish to PyPI when a GitHub release is created | |
| # 1. Create a PyPI API token: https://pypi.org/manage/account/token/ | |
| # 2. Add it under environment "pypi": Settings → Environments → pypi → Environment secrets → PYPI_API_TOKEN | |
| name: Publish to PyPI | |
| on: | |
| release: | |
| types: [published] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Set version from release tag | |
| run: | | |
| TAG="${{ github.event.release.tag_name }}" | |
| VERSION="${TAG#v}" | |
| sed -i "s/^version = .*/version = \"${VERSION}\"/" pyproject.toml | |
| echo "Building version ${VERSION}" | |
| grep '^version = ' pyproject.toml | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| - name: Install build tools | |
| run: pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* |