Skip to content

Commit 7d425ce

Browse files
authored
adde pypi workflow
1 parent 7c48c4e commit 7d425ce

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

.github/workflows/pypi.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: upload-pypi
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
id-token: write
10+
11+
12+
jobs:
13+
release-build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Set version from release tag
18+
run: echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.x"
24+
25+
- name: Build release distributions
26+
run: |
27+
# NOTE: put your own distribution build steps here.
28+
python -m pip install build
29+
python -m build
30+
31+
- name: Upload distributions
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: release-dists
35+
path: dist/
36+
37+
pypi-publish:
38+
runs-on: ubuntu-latest
39+
needs:
40+
- release-build
41+
permissions:
42+
# IMPORTANT: this permission is mandatory for trusted publishing
43+
id-token: write
44+
45+
# Dedicated environments with protections for publishing are strongly recommended.
46+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
47+
environment:
48+
name: pypi
49+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
50+
#url: https://pypi.org/p/${GITHUB_REPOSITORY#*/}
51+
#
52+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
53+
# ALTERNATIVE: exactly, uncomment the following line instead:
54+
url: https://pypi.org/project/${GITHUB_REPOSITORY#*/}/${{ github.event.release.name }}
55+
56+
steps:
57+
- name: Retrieve release distributions
58+
uses: actions/download-artifact@v4
59+
with:
60+
name: release-dists
61+
path: dist/
62+
63+
- name: Publish release distributions to PyPI
64+
uses: pypa/gh-action-pypi-publish@release/v1
65+
with:
66+
packages-dir: dist/
67+
sign-package:
68+
runs-on: ubuntu-latest
69+
needs:
70+
- release-build
71+
steps:
72+
- name: Download all the dists
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: release-dists
76+
path: dist/
77+
- name: Sign the dists with Sigstore
78+
uses: sigstore/gh-action-sigstore-python@v3.0.0
79+
with:
80+
inputs: >-
81+
./dist/*.tar.gz
82+
./dist/*.whl
83+
publish-to-testpypi:
84+
name: Publish Python 🐍 distribution 📦 to TestPyPI
85+
needs:
86+
- release-build
87+
runs-on: ubuntu-latest
88+
89+
environment:
90+
name: testpypi
91+
url: https://test.pypi.org/p/${GITHUB_REPOSITORY#*/}
92+
93+
permissions:
94+
id-token: write # IMPORTANT: mandatory for trusted publishing
95+
96+
steps:
97+
- name: Download all the dists
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: release-dists
101+
path: dist/
102+
- name: Publish distribution 📦 to TestPyPI
103+
uses: pypa/gh-action-pypi-publish@release/v1
104+
with:
105+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)