99name : Upload Python Package
1010
1111on :
12- release :
13- types : [published, created, released]
12+ workflow_run :
13+ workflows : ["Auto Release"]
14+ types :
15+ - completed
1416
1517permissions :
1618 contents : read
1719
1820jobs :
21+ check-workflow :
22+ runs-on : ubuntu-latest
23+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
24+ outputs :
25+ version : ${{ steps.get-version.outputs.version }}
26+ should_publish : ${{ steps.check-release.outputs.should_publish }}
27+
28+ steps :
29+ - uses : actions/checkout@v4
30+ with :
31+ fetch-depth : 0
32+ ref : ${{ github.event.workflow_run.head_branch }}
33+
34+ - name : Get version from pyproject.toml
35+ id : get-version
36+ run : |
37+ VERSION=$(grep -m 1 "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
38+ echo "version=$VERSION" >> $GITHUB_OUTPUT
39+ echo "Current version: $VERSION"
40+
41+ - name : Check if release should be published
42+ id : check-release
43+ run : |
44+ # Check if most recent commit was a version bump
45+ COMMIT_MSG=$(git log -1 --pretty=%B)
46+ if [[ "$COMMIT_MSG" =~ [Bb][Uu][Mm][Pp]\ [Vv][Ee][Rr][Ss][Ii][Oo][Nn] ]]; then
47+ echo "should_publish=true" >> $GITHUB_OUTPUT
48+ echo "Version bump detected, should publish to PyPI"
49+ else
50+ echo "should_publish=false" >> $GITHUB_OUTPUT
51+ echo "Not a version bump commit, skipping PyPI publishing"
52+ fi
53+
54+ - name : Debug workflow info
55+ run : |
56+ echo "Auto-Release workflow completed successfully"
57+ echo "Version to publish: ${{ steps.get-version.outputs.version }}"
58+ echo "Should publish: ${{ steps.check-release.outputs.should_publish }}"
59+
1960 release-build :
2061 runs-on : ubuntu-latest
62+ needs : check-workflow
63+ if : ${{ needs.check-workflow.outputs.should_publish == 'true' }}
2164
2265 steps :
2366 - uses : actions/checkout@v4
67+ with :
68+ ref : ${{ github.event.workflow_run.head_branch }}
2469
2570 - uses : actions/setup-python@v5
2671 with :
27- python-version : " 3.x "
72+ python-version : " 3.11 "
2873
2974 - name : Build release distributions
3075 run : |
76+ python -m pip install --upgrade pip
3177 python -m pip install build
3278 python -m build
3379
4086 pypi-publish :
4187 runs-on : ubuntu-latest
4288 needs :
89+ - check-workflow
4390 - release-build
91+ if : ${{ needs.check-workflow.outputs.should_publish == 'true' }}
4492 environment :
4593 name : pypi
4694
56104 with :
57105 password : ${{ secrets.PYPI_TOKEN }}
58106 packages-dir : dist/
59- verbose : true
107+ verbose : true
108+
109+ - name : Publish success
110+ run : |
111+ echo "✅ Successfully published version ${{ needs.check-workflow.outputs.version }} to PyPI"
0 commit comments