Skip to content

Commit f4075a9

Browse files
ci: convert to OIDC trusted publishing via pypa/gh-action-pypi-publish
Replaces token-based twine upload with OpenID Connect (OIDC) trusted publishing using pypa/gh-action-pypi-publish@release/v1. This eliminates the need for PYPI_API_TOKEN and TEST_PYPI_API_TOKEN secrets. Human step: register the repo at pypi.org as a trusted publisher.
1 parent f3cd3a1 commit f4075a9

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

.github/workflows/publish.yml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,43 @@ on:
1414
- testpypi
1515

1616
jobs:
17-
build-and-publish:
17+
publish:
1818
runs-on: ubuntu-latest
19+
environment: pypi
1920
permissions:
20-
contents: read
2121
id-token: write
2222

2323
steps:
2424
- uses: actions/checkout@v4
2525
with:
2626
persist-credentials: false
2727

28-
- name: Set up Python 3.11
28+
- name: Set up Python 3.12
2929
uses: actions/setup-python@v5
3030
with:
31-
python-version: "3.11"
31+
python-version: "3.12"
3232

33-
- name: Install build deps
33+
- name: Install dependencies
3434
run: |
35+
python -m pip install --upgrade pip
3536
pip install build twine
3637
3738
- name: Lint with ruff
3839
run: pip install ruff && ruff check src/ --target-version py310
3940

4041
- name: Build package
41-
run: |
42-
python -m build
42+
run: python -m build
4343

44-
- name: Publish to PyPI
45-
if: ${{ inputs.pypi_target != 'testpypi' || github.event_name == 'release' }}
46-
env:
47-
TWINE_USERNAME: __token__
48-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
49-
run: |
50-
twine upload dist/* --verbose
44+
- name: Check package
45+
run: twine check dist/*
5146

5247
- name: Publish to TestPyPI
5348
if: ${{ inputs.pypi_target == 'testpypi' }}
54-
env:
55-
TWINE_USERNAME: __token__
56-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
57-
run: |
58-
twine upload --repository testpypi dist/* --verbose
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
52+
53+
- name: Publish to PyPI
54+
if: ${{ inputs.pypi_target == 'pypi' || github.event_name == 'release' }}
55+
uses: pypa/gh-action-pypi-publish@release/v1
5956

0 commit comments

Comments
 (0)