diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 9e5292b5..b7310ab8 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -119,3 +119,36 @@ jobs: prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} generate_release_notes: true files: release/** + + publish-pypi: + needs: build + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + environment: pypi + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + + - uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2 + + - name: Verify tag matches package version + shell: bash + run: | + VERSION="$(uv run python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" + TAG_VERSION="${GITHUB_REF_NAME#v}" + if [[ "${TAG_VERSION}" != "${VERSION}" ]]; then + echo "::error::Tag ${GITHUB_REF_NAME} does not match pyproject.toml version ${VERSION}" + exit 1 + fi + + - name: Build Python distribution + shell: bash + run: uv build + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@ba38be9e461d3875417946c167d0b5f3d385a247 # v1.14.1