Skip to content

Commit 5c39d55

Browse files
committed
ci: move to PyPy Trusted Publishing
Move to PyPi Trusted Publishing using an ID token instead of relying on a fixed token. Split the release workflow in 3 steps: - build phase with poetry, followed by an artifact upload - publication to PyPi by pulling built artifacts first - publications to Test PyPi by pulling built artifacts first This follows official guidance from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
1 parent 65f5e26 commit 5c39d55

1 file changed

Lines changed: 54 additions & 15 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: PyPI Publish
22

33
on:
44
release:
5-
types: [published]
5+
types: [created]
66
workflow_dispatch:
77
inputs:
88
test_release:
@@ -12,26 +12,65 @@ on:
1212
type: boolean
1313

1414
jobs:
15-
publish:
15+
build:
16+
name: Build distribution
1617
runs-on: ubuntu-latest
18+
1719
steps:
1820
- uses: actions/checkout@v6
19-
- name: Install uv & Python
21+
with:
22+
persist-credentials: false
23+
- name: Install uv
2024
uses: astral-sh/setup-uv@v7
2125
with:
2226
enable-cache: true
2327
cache-dependency-glob: "uv.lock"
24-
- run: uv build
28+
- name: Build distribution
29+
run: uv build
30+
- name: Store distribution packages
31+
uses: actions/upload-artifact@v5
32+
with:
33+
name: python-package-distributions
34+
path: dist/
35+
36+
publish-to-pypi:
37+
name: Publish distribution to PyPI
38+
if: github.event_name == 'release'
39+
needs: build
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/p/onekey_client
44+
permissions:
45+
id-token: write
46+
47+
steps:
48+
- name: Download distribution packages
49+
uses: actions/download-artifact@v6
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- name: Publish distribution to PyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
2555

26-
- name: Publish to TestPyPI
27-
if: ${{ github.event_name == 'workflow_dispatch' && inputs.test_release == true }}
28-
run: uv publish
29-
env:
30-
UV_PUBLISH_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
31-
UV_PUBLISH_URL: https://test.pypi.org/legacy/
56+
publish-to-testpypi:
57+
name: Publish distribution to TestPyPI
58+
if: github.event_name == 'workflow_dispatch' && inputs.test_release
59+
needs: build
60+
runs-on: ubuntu-latest
61+
environment:
62+
name: testpypi
63+
url: https://test.pypi.org/p/onekey_client
64+
permissions:
65+
id-token: write
3266

33-
- name: Publish to PyPI
34-
if: ${{ github.event_name != 'workflow_dispatch' || inputs.test_release == false }}
35-
run: uv publish
36-
env:
37-
UV_PUBLISH_TOKEN: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
67+
steps:
68+
- name: Download distribution packages
69+
uses: actions/download-artifact@v6
70+
with:
71+
name: python-package-distributions
72+
path: dist/
73+
- name: Publish distribution to TestPyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1
75+
with:
76+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)