55 tags :
66 - " v[0-9]*"
77 - " test*"
8+ workflow_dispatch :
9+ inputs :
10+ destination :
11+ description : " Publish destination"
12+ required : true
13+ default : testpypi
14+ type : choice
15+ options :
16+ - testpypi
17+ - pypi
818
919jobs :
1020 build-wheels :
7686 name : cibw-sdist
7787 path : dist/*.tar.gz
7888
79- test_sdist :
89+ test-sdist :
8090 name : Test SDist
8191 needs : make_sdist
8292 runs-on : ubuntu-latest
@@ -99,19 +109,12 @@ jobs:
99109 run : pip install dist/*.tar.gz
100110
101111 publish :
102- name : Publish to PyPI
103- needs : [build-wheels, test_sdist ]
112+ name : Publish
113+ needs : [build-wheels, test-sdist ]
104114 runs-on : ubuntu-latest
105115 permissions :
106116 id-token : write
107- contents : read
108117 steps :
109- - name : Checkout tagged source
110- uses : actions/checkout@v5
111- with :
112- ref : ${{ github.ref }}
113- fetch-depth : 0
114-
115118 - name : Download wheels
116119 uses : actions/download-artifact@v4
117120 with :
@@ -125,17 +128,28 @@ jobs:
125128 name : cibw-sdist
126129 path : dist
127130
128- - name : Publish to TestPyPI (test tags)
129- if : startsWith(github.ref, 'refs/tags/test')
131+ - name : Resolve publish config
132+ id : config
133+ run : |
134+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
135+ testpypi="${{ inputs.destination == 'testpypi' }}"
136+ elif [[ "${{ github.ref }}" == refs/tags/test* || "${{ github.ref_name }}" == *rc* ]]; then
137+ testpypi="true"
138+ else
139+ testpypi="false"
140+ fi
141+ if [[ "$testpypi" == "true" ]]; then
142+ echo "repo-url=https://test.pypi.org/legacy/" >> "$GITHUB_OUTPUT"
143+ echo "skip-existing=true" >> "$GITHUB_OUTPUT"
144+ else
145+ echo "repo-url=https://upload.pypi.org/legacy/" >> "$GITHUB_OUTPUT"
146+ echo "skip-existing=false" >> "$GITHUB_OUTPUT"
147+ fi
148+
149+ - name : Publish
130150 uses : pypa/gh-action-pypi-publish@release/v1
131151 with :
132- repository-url : https://test.pypi.org/legacy/
152+ repository-url : ${{ steps.config.outputs.repo-url }}
133153 packages-dir : dist
134- skip-existing : true
154+ skip-existing : ${{ steps.config.outputs.skip-existing }}
135155 verbose : true
136-
137- - name : Publish to PyPI (real releases)
138- if : startsWith(github.ref, 'refs/tags/v')
139- uses : pypa/gh-action-pypi-publish@release/v1
140- with :
141- packages-dir : dist
0 commit comments