Skip to content

Commit 9df345f

Browse files
authored
Merge pull request #81 from onekey-sec/trusted-publishing
ci: move to PyPy Trusted Publishing
2 parents 65f5e26 + 1aa143e commit 9df345f

1 file changed

Lines changed: 82 additions & 26 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 82 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,93 @@
1-
name: PyPI Publish
1+
name: Publish Python distribution
22

33
on:
4-
release:
5-
types: [published]
6-
workflow_dispatch:
7-
inputs:
8-
test_release:
9-
description: If true, publish to test.pypi.org
10-
required: true
11-
default: true
12-
type: boolean
4+
push:
5+
branches: [master]
6+
tags: ["*"]
7+
8+
permissions:
9+
contents: read
10+
11+
# Publishing runs must not be cancelled: every default-branch push gets a
12+
# distinct TestPyPI version.
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.run_id }}
15+
cancel-in-progress: false
16+
17+
env:
18+
PACKAGE_NAME: onekey_client
1319

1420
jobs:
15-
publish:
21+
build:
22+
name: Build distribution
1623
runs-on: ubuntu-latest
1724
steps:
1825
- uses: actions/checkout@v6
19-
- name: Install uv & Python
26+
with:
27+
persist-credentials: false
28+
- name: Install uv
2029
uses: astral-sh/setup-uv@v7
2130
with:
2231
enable-cache: true
2332
cache-dependency-glob: "uv.lock"
24-
- run: uv build
25-
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/
32-
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 }}
33+
- name: Build distribution
34+
run: uv build
35+
- name: Store distribution packages
36+
uses: actions/upload-artifact@v5
37+
38+
publish-to-testpypi:
39+
name: Publish distribution to TestPyPI
40+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
41+
needs: build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: testpypi
45+
url: https://test.pypi.org/p/onekey_client
46+
permissions:
47+
id-token: write
48+
steps:
49+
- uses: actions/download-artifact@v6
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- uses: pypa/gh-action-pypi-publish@release/v1
54+
with:
55+
repository-url: https://test.pypi.org/legacy/
56+
57+
publish-to-pypi:
58+
name: Publish distribution to PyPI
59+
needs: build
60+
if: startsWith(github.ref, 'refs/tags/')
61+
runs-on: ubuntu-latest
62+
environment:
63+
name: pypi
64+
url: https://pypi.org/p/onekey_client
65+
permissions:
66+
id-token: write
67+
steps:
68+
- uses: actions/download-artifact@v6
69+
with:
70+
name: python-package-distributions
71+
path: dist/
72+
- uses: pypa/gh-action-pypi-publish@release/v1
73+
74+
release:
75+
name: Create GitHub Release
76+
if: startsWith(github.ref, 'refs/tags/')
77+
needs: [build, publish-to-pypi]
78+
runs-on: ubuntu-latest
79+
permissions:
80+
attestations: write
81+
contents: write
82+
id-token: write
83+
steps:
84+
- uses: actions/download-artifact@v6
85+
with:
86+
name: python-package-distributions
87+
path: dist/
88+
- uses: actions/attest-build-provenance@v3
89+
with:
90+
subject-path: dist/*
91+
- env:
92+
GH_TOKEN: ${{ github.token }}
93+
run: gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes dist/*

0 commit comments

Comments
 (0)