Skip to content

Commit f6d5bc1

Browse files
authored
Update PyPI release to trusted publishing (#1752)
1 parent 8e669cc commit f6d5bc1

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ jobs:
10141014
name: Release
10151015
environment: release
10161016
runs-on: ubuntu-latest
1017+
permissions:
1018+
contents: write
1019+
id-token: write
10171020
needs: [analyze, test_linux, test_macos, test_windows, test_python_latest_supported, test_python_312, test_python_311, test_python_310, test_qt_gui, test_packaging, test_code_quality, build_linux, build_macos, build_windows]
10181021
if: >-
10191022
!cancelled()
@@ -1059,15 +1062,16 @@ jobs:
10591062
RELEASE_VERSION: ${{ needs.test_packaging.outputs.version }}
10601063
run: publish_github_release
10611064

1062-
- name: Publish PyPI release
1065+
- name: Collect Python distributions for PyPI
1066+
run: |
1067+
mkdir -p dist/pypi
1068+
cp dist/Source/*.tar.gz dist/pypi/
1069+
cp dist/Wheel/*.whl dist/pypi/
1070+
1071+
- name: Publish release to PyPI (Trusted Publishing)
10631072
if: needs.analyze.outputs.release_type == 'tagged'
1064-
env:
1065-
TWINE_NON_INTERACTIVE: 1
1066-
TWINE_USERNAME: __token__
1067-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
1068-
# Optional: twine will fallback to default if empty.
1069-
TWINE_REPOSITORY_URL: ${{ secrets.PYPI_URL }}
1070-
run: publish_pypi_release
1073+
uses: pypa/gh-action-pypi-publish@release/v1
1074+
with:
1075+
packages-dir: dist/pypi
1076+
skip-existing: true
10711077
# }}}
1072-
1073-
# vim: foldmethod=marker foldlevel=0

.github/workflows/ci/helpers.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ EOF
190190
"$tag" "${assets[@]}"
191191
}
192192

193-
publish_pypi_release()
194-
{
195-
run "$python" -m twine upload dist/Source/* dist/Wheel/*
196-
}
197-
198193
analyze_set_release_info()
199194
{
200195
info "GITHUB_REF: $GITHUB_REF"

.github/workflows/ci/workflow_generate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def fetch_anchor(self):
8686
)
8787
fp.write(workflow)
8888

89+
# Ensure the generated file ends with a trailing newline.
90+
fp.write("\n")
91+
8992
# And try parsing it to check it's valid YAML,
9093
# and ensure anchors/aliases are not used.
9194
GithubActionsYamlLoader(workflow).get_single_data()

.github/workflows/ci/workflow_template.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ jobs:
274274
name: Release
275275
environment: release
276276
runs-on: ubuntu-latest
277+
permissions:
278+
contents: write
279+
id-token: write
277280
needs: [analyze, <@ jobs|join(', ', attribute='id') @>]
278281
if: >-
279282
!cancelled()
@@ -309,15 +312,16 @@ jobs:
309312
RELEASE_VERSION: ${{ needs.test_packaging.outputs.version }}
310313
run: publish_github_release
311314

312-
- name: Publish PyPI release
315+
- name: Collect Python distributions for PyPI
316+
run: |
317+
mkdir -p dist/pypi
318+
cp dist/Source/*.tar.gz dist/pypi/
319+
cp dist/Wheel/*.whl dist/pypi/
320+
321+
- name: Publish release to PyPI (Trusted Publishing)
313322
if: needs.analyze.outputs.release_type == 'tagged'
314-
env:
315-
TWINE_NON_INTERACTIVE: 1
316-
TWINE_USERNAME: __token__
317-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
318-
# Optional: twine will fallback to default if empty.
319-
TWINE_REPOSITORY_URL: ${{ secrets.PYPI_URL }}
320-
run: publish_pypi_release
323+
uses: pypa/gh-action-pypi-publish@release/v1
324+
with:
325+
packages-dir: dist/pypi
326+
skip-existing: true
321327
# }}}
322-
323-
# vim: foldmethod=marker foldlevel=0

0 commit comments

Comments
 (0)