Skip to content

Commit 061e7ab

Browse files
ci: restructure publish-python to reduce duplication
Instead of having two mostly-identical jobs for publishing to PyPI (one for prod one for test), have one job and take an environment selector as a workflow input.
1 parent 94a21f1 commit 061e7ab

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

Diff for: .github/workflows/publish-python.yml

+13-40
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ on:
1212
description: "Upload generate package files to PyPI"
1313
required: true
1414
type: boolean
15-
use_prod_pypi:
16-
description: "Use production PyPI not Test PyPI"
17-
required: false
18-
type: boolean
15+
pypi_environment:
16+
description: "Which PyPI instance to publish to"
17+
required: true
18+
type: choice
19+
options:
20+
- testpypi
21+
- pypi
1922

2023
jobs:
2124
build_sdist:
@@ -72,17 +75,17 @@ jobs:
7275
path: ./wheelhouse/*.whl
7376
if-no-files-found: error
7477

75-
upload_to_prod_pypi:
76-
name: Upload packages to PyPI
78+
upload_to_pypi:
79+
name: "Upload packages to PyPI"
7780
needs: [build_sdist, build_wheels]
7881
runs-on: ubuntu-24.04
79-
if: "${{ inputs.upload_to_pypi && inputs.use_prod_pypi && startsWith(github.ref, 'refs/tags') }}"
82+
if: "${{ inputs.upload_to_pypi }}"
8083
permissions:
8184
contents: read
8285
id-token: write # Needed for PyPI Trusted Publishing
8386
environment:
84-
name: pypi
85-
url: https://pypi.org/p/jsonnet
87+
name: "${{ inputs.pypi_environment }}"
88+
url: "${{ inputs.pypi_environment == 'pypi' && 'https://pypi.org/p/jsonnet' || 'https://test.pypi.org/p/jsonnet' }}"
8689
steps:
8790
- uses: actions/download-artifact@v4
8891
with:
@@ -98,38 +101,8 @@ jobs:
98101
find cibw-wheels/ -type f -name '*.whl' -exec mv '{}' ./dist/ ';'
99102
find sdist/ -type f -name '*.gz' -exec mv '{}' ./dist/ ';'
100103
- name: Publish to PyPI
101-
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
102-
with:
103-
print-hash: true
104-
105-
upload_to_test_pypi:
106-
name: Upload packages to TEST PyPI
107-
needs: [build_sdist, build_wheels]
108-
runs-on: ubuntu-24.04
109-
if: "${{ inputs.upload_to_pypi && !inputs.use_prod_pypi }}"
110-
permissions:
111-
contents: read
112-
id-token: write # Needed for PyPI Trusted Publishing
113-
environment:
114-
name: testpypi
115-
url: https://test.pypi.org/p/jsonnet
116-
steps:
117-
- uses: actions/download-artifact@v4
118-
with:
119-
path: cibw-wheels
120-
pattern: cibw-wheels-*
121-
- uses: actions/download-artifact@v4
122-
with:
123-
path: sdist
124-
name: sdist
125-
- name: Flatten wheels to one directory
126-
run: |
127-
mkdir dist
128-
find cibw-wheels/ -type f -name '*.whl' -exec mv '{}' ./dist/ ';'
129-
find sdist/ -type f -name '*.gz' -exec mv '{}' ./dist/ ';'
130-
- name: Publish to TEST PyPI
131104
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
132105
with:
133106
verbose: true
134107
print-hash: true
135-
repository-url: https://test.pypi.org/legacy/
108+
repository-url: "${{ inputs.pypi_environment == 'testpypi' && 'https://test.pypi.org/legacy/' || '' }}"

0 commit comments

Comments
 (0)