11name : Publish to PyPI
22
33on :
4+ release :
5+ types : [published]
46 workflow_dispatch :
57 inputs :
68 version :
7- description : ' Version tag to publish (e.g., v0.2 .0)'
9+ description : ' Version tag (e.g., v0.8.0 or 0.8 .0)'
810 required : true
911 type : string
1012
@@ -15,19 +17,34 @@ jobs:
1517 permissions :
1618 id-token : write
1719 steps :
20+ - name : Normalize version
21+ id : version
22+ run : |
23+ if [ "${{ github.event_name }}" = "release" ]; then
24+ TAG="${{ github.event.release.tag_name }}"
25+ else
26+ TAG="${{ inputs.version }}"
27+ fi
28+ # Ensure tag has v prefix
29+ TAG_VERSION="${TAG#v}"
30+ TAG_VERSION="v${TAG_VERSION}"
31+ # Bare version for pyproject.toml comparison
32+ BARE_VERSION="${TAG_VERSION#v}"
33+ echo "tag=${TAG_VERSION}" >> "$GITHUB_OUTPUT"
34+ echo "bare=${BARE_VERSION}" >> "$GITHUB_OUTPUT"
35+ echo "Publishing version: ${TAG_VERSION} (${BARE_VERSION})"
36+
1837 - uses : actions/checkout@v4
1938 with :
20- ref : ${{ inputs .version }}
39+ ref : ${{ steps .version.outputs.tag }}
2140
2241 - uses : astral-sh/setup-uv@v4
2342
2443 - name : Verify version matches pyproject.toml
2544 run : |
2645 TOML_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
27- INPUT_VERSION="${{ inputs.version }}"
28- INPUT_VERSION="${INPUT_VERSION#v}"
29- if [ "$TOML_VERSION" != "$INPUT_VERSION" ]; then
30- echo "Error: Input version ($INPUT_VERSION) doesn't match pyproject.toml ($TOML_VERSION)"
46+ if [ "$TOML_VERSION" != "${{ steps.version.outputs.bare }}" ]; then
47+ echo "Error: Tag version (${{ steps.version.outputs.bare }}) doesn't match pyproject.toml ($TOML_VERSION)"
3148 exit 1
3249 fi
3350 working-directory : python
0 commit comments