Skip to content

Commit 372d8e2

Browse files
ad-mAdam Dobrawyclaude
authored
ci: switch to PyPI Trusted Publishing (OIDC) (#113)
Replace API token-based authentication with OpenID Connect trusted publishing. This eliminates the need for stored PyPI secrets and improves supply chain security. Co-authored-by: Adam Dobrawy <naczelnik@jawne.info.pl> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8ab233d commit 372d8e2

1 file changed

Lines changed: 56 additions & 21 deletions

File tree

.github/workflows/publish.yml

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,70 @@
1-
name: Publish Python 🐍 package
1+
name: Publish Python package
22

3-
on: [push]
3+
on:
4+
push:
5+
tags:
6+
- '*'
47

58
jobs:
6-
build-n-publish:
9+
build:
10+
name: Build distribution
711
runs-on: ubuntu-latest
812
steps:
9-
- uses: actions/checkout@v1
13+
- uses: actions/checkout@v4
1014

11-
- name: Set up Python 3.7
12-
uses: actions/setup-python@v1
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
1317
with:
14-
python-version: "3.7"
18+
python-version: "3.12"
1519

16-
- name: Install setup dependencies
17-
run: pip install setuptools_scm wheel
20+
- name: Install build dependencies
21+
run: pip install setuptools setuptools_scm wheel build
1822

1923
- name: Build distribution
20-
run: make build
24+
run: python -m build
2125

22-
- name: Publish distribution 📦 to PyPI
23-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
24-
uses: pypa/gh-action-pypi-publish@master
26+
- name: Store distribution packages
27+
uses: actions/upload-artifact@v4
2528
with:
26-
user: __token__
27-
password: ${{ secrets.pypi_password }}
29+
name: python-package-distributions
30+
path: dist/
2831

29-
- name: Publish distribution 📦 to Test PyPI
30-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
31-
uses: pypa/gh-action-pypi-publish@master
32+
publish-to-pypi:
33+
name: Publish to PyPI
34+
needs: build
35+
runs-on: ubuntu-latest
36+
environment:
37+
name: pypi
38+
url: https://pypi.org/p/python-anticaptcha
39+
permissions:
40+
id-token: write
41+
steps:
42+
- name: Download distribution packages
43+
uses: actions/download-artifact@v4
44+
with:
45+
name: python-package-distributions
46+
path: dist/
47+
48+
- name: Publish to PyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
51+
publish-to-testpypi:
52+
name: Publish to TestPyPI
53+
needs: build
54+
runs-on: ubuntu-latest
55+
environment:
56+
name: testpypi
57+
url: https://test.pypi.org/p/python-anticaptcha
58+
permissions:
59+
id-token: write
60+
steps:
61+
- name: Download distribution packages
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: python-package-distributions
65+
path: dist/
66+
67+
- name: Publish to TestPyPI
68+
uses: pypa/gh-action-pypi-publish@release/v1
3269
with:
33-
user: __token__
34-
password: ${{ secrets.test_pypi_password }}
35-
repository_url: https://test.pypi.org/legacy/
70+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)