11name : Publish Python Packages
22
33on :
4+ push :
5+ tags :
6+ - " **"
47 workflow_dispatch :
58 inputs :
69 version :
5659
5760 echo "version=$version" >> "$GITHUB_OUTPUT"
5861
62+ resolve-target :
63+ runs-on : ubuntu-latest
64+ outputs :
65+ target : ${{ steps.resolve.outputs.target }}
66+ steps :
67+ - name : Resolve publish target
68+ id : resolve
69+ shell : bash
70+ env :
71+ INPUT_TARGET : ${{ github.event.inputs.target }}
72+ REF_TYPE : ${{ github.ref_type }}
73+ run : |
74+ target="${INPUT_TARGET}"
75+ if [ -z "$target" ]; then
76+ if [ "$REF_TYPE" = "tag" ]; then
77+ target="all"
78+ else
79+ echo "::error::Set the target input or run this workflow on a tag ref."
80+ exit 1
81+ fi
82+ fi
83+
84+ case "$target" in
85+ bootstrap-1|bootstrap-2|all) ;;
86+ *)
87+ echo "::error::Expected target to be one of bootstrap-1, bootstrap-2, all; got: $target"
88+ exit 1
89+ ;;
90+ esac
91+
92+ echo "target=$target" >> "$GITHUB_OUTPUT"
93+
5994 version-check :
60- needs : resolve-version
95+ needs :
96+ - resolve-version
97+ - resolve-target
6198 runs-on : ubuntu-latest
6299 permissions :
63100 contents : read
74111 build-package :
75112 needs :
76113 - resolve-version
114+ - resolve-target
77115 - version-check
78116 strategy :
79117 matrix :
@@ -110,15 +148,15 @@ jobs:
110148 uses : dtolnay/rust-toolchain@1.94.0
111149
112150 - name : Build distribution
113- if : ${{ github.event.inputs .target == 'all' || (github.event.inputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (github.event.inputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
151+ if : ${{ needs.resolve-target.outputs .target == 'all' || (needs.resolve-target.outputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (needs.resolve-target.outputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
114152 run : uv build "${{ matrix.package_path }}" --out-dir dist
115153
116154 - name : Check distribution metadata
117- if : ${{ github.event.inputs .target == 'all' || (github.event.inputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (github.event.inputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
155+ if : ${{ needs.resolve-target.outputs .target == 'all' || (needs.resolve-target.outputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (needs.resolve-target.outputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
118156 run : uvx twine check dist/*
119157
120158 - name : Upload distributions
121- if : ${{ github.event.inputs .target == 'all' || (github.event.inputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (github.event.inputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
159+ if : ${{ needs.resolve-target.outputs .target == 'all' || (needs.resolve-target.outputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (needs.resolve-target.outputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
122160 uses : actions/upload-artifact@v4
123161 with :
124162 name : ${{ env.PURE_PYTHON_ARTIFACT_PREFIX }}-${{ matrix.package_path }}
@@ -127,8 +165,9 @@ jobs:
127165 build-bindings-wheels :
128166 needs :
129167 - resolve-version
168+ - resolve-target
130169 - version-check
131- if : ${{ github.event.inputs .target == 'all' || github.event.inputs .target == 'bootstrap-1' }}
170+ if : ${{ needs.resolve-target.outputs .target == 'all' || needs.resolve-target.outputs .target == 'bootstrap-1' }}
132171 strategy :
133172 matrix :
134173 include :
@@ -197,8 +236,9 @@ jobs:
197236 build-bindings-sdist :
198237 needs :
199238 - resolve-version
239+ - resolve-target
200240 - version-check
201- if : ${{ github.event.inputs .target == 'all' || github.event.inputs .target == 'bootstrap-1' }}
241+ if : ${{ needs.resolve-target.outputs .target == 'all' || needs.resolve-target.outputs .target == 'bootstrap-1' }}
202242 runs-on : ubuntu-latest
203243 permissions :
204244 contents : read
@@ -251,31 +291,34 @@ jobs:
251291 publish_in_bootstrap_1 : false
252292 publish_in_bootstrap_2 : true
253293 runs-on : ubuntu-latest
254- needs : build-package
294+ needs :
295+ - resolve-target
296+ - build-package
255297 environment :
256298 name : ${{ matrix.environment_name }}
257299 permissions :
258300 id-token : write
259301 steps :
260302 - name : Download distributions
261- if : ${{ github.event.inputs .target == 'all' || (github.event.inputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (github.event.inputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
303+ if : ${{ needs.resolve-target.outputs .target == 'all' || (needs.resolve-target.outputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (needs.resolve-target.outputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
262304 uses : actions/download-artifact@v8
263305 with :
264306 name : ${{ env.PURE_PYTHON_ARTIFACT_PREFIX }}-${{ matrix.package_path }}
265307 path : dist/
266308
267309 - name : Publish to PyPI
268- if : ${{ github.event.inputs .target == 'all' || (github.event.inputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (github.event.inputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
310+ if : ${{ needs.resolve-target.outputs .target == 'all' || (needs.resolve-target.outputs .target == 'bootstrap-1' && matrix.publish_in_bootstrap_1) || (needs.resolve-target.outputs .target == 'bootstrap-2' && matrix.publish_in_bootstrap_2) }}
269311 uses : pypa/gh-action-pypi-publish@release/v1
270312 with :
271313 skip-existing : true
272314
273315 publish-bindings :
274316 runs-on : ubuntu-latest
275317 needs :
318+ - resolve-target
276319 - build-bindings-wheels
277320 - build-bindings-sdist
278- if : ${{ github.event.inputs .target == 'all' || github.event.inputs .target == 'bootstrap-1' }}
321+ if : ${{ needs.resolve-target.outputs .target == 'all' || needs.resolve-target.outputs .target == 'bootstrap-1' }}
279322 environment :
280323 name : pypi-tstring-bindings
281324 permissions :
0 commit comments