@@ -7,21 +7,23 @@ name: "Publish to PyPI"
77
88on :
99 workflow_dispatch :
10- target :
11- inputs :
10+ inputs :
1211 target :
1312 description : ' Target'
1413 required : true
1514 default : ' PyPI'
1615 type : choice
1716 options :
1817 - PyPI
19- - TestPyPi
18+ - TestPyPI
2019 # push:
2120 # tags:
2221 # # Publish on any tag starting with a `v`, e.g., v0.1.0
2322 # - v*
2423
24+ env :
25+ BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
26+
2527run-name : Publish to ${{ inputs.target }}
2628
2729jobs :
3335 id-token : write
3436 contents : read
3537 steps :
38+ - name : Verify branch
39+ run : |
40+ echo "Branch name is $BRANCH_NAME"
41+ if [ "${{ inputs.target }}" == "PyPI" ] && [ "$BRANCH_NAME" != "main" ]; then
42+ echo "::error title=Invalid branch::Only the main branch can be published to PyPI."
43+ exit 1
44+ fi
3645 - name : Checkout
3746 uses : actions/checkout@v5
3847 - name : Install uv
@@ -41,13 +50,13 @@ jobs:
4150 run : uv build
4251 # Check that basic features work and we didn't miss to include crucial files
4352 - name : Smoke test (wheel)
44- run : uv run --isolated --no-project --with dist/*.whl tests /smoke_test.py
53+ run : uv run --isolated --no-project --with dist/*.whl test /smoke_test.py
4554 - name : Smoke test (source distribution)
46- run : uv run --isolated --no-project --with dist/*.tar.gz tests /smoke_test.py
55+ run : uv run --isolated --no-project --with dist/*.tar.gz test /smoke_test.py
4756 - name : Publish
48- run : uv publish ${{ inputs.target == 'TestPyPi ' && '--index testpypi' || '' }}
57+ run : uv publish ${{ inputs.target == 'TestPyPI ' && '--index testpypi' || '' }}
4958 - name : Summary
5059 run : |
5160 echo "### Published OpenTSLM to ${{ inputs.target }} :rocket:" >> $GITHUB_STEP_SUMMARY
5261 echo "Version: `$(uv version --short)`" >> $GITHUB_STEP_SUMMARY
53- echo "URL: https://${{ inputs.target == 'TestPyPi ' && 'test.' || '' }}pypi.org/project/opentslm/$(uv version --short)/" >>> $GITHUB_STEP_SUMMARY
62+ echo "URL: https://${{ inputs.target == 'TestPyPI ' && 'test.' || '' }}pypi.org/project/opentslm/$(uv version --short)/" >>> $GITHUB_STEP_SUMMARY
0 commit comments