Skip to content

Commit 33e88a3

Browse files
committed
added publish-to-pypi.yml
1 parent bd67907 commit 33e88a3

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build distribution 📦
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
persist-credentials: false
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m pip install build --user
21+
- name: Build a binary wheel and a source tarball
22+
run: python3 -m build
23+
- name: Store the distribution packages
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: python-package-distributions
27+
path: dist/
28+
29+
publish-to-pypi:
30+
name: >-
31+
Publish Python 🐍 distribution 📦 to PyPI
32+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
33+
needs:
34+
- build
35+
runs-on: ubuntu-latest
36+
environment:
37+
name: pypi
38+
url: https://pypi.org/p/pyeleven
39+
permissions:
40+
id-token: write # IMPORTANT: mandatory for trusted publishing
41+
42+
steps:
43+
- name: Download all the dists
44+
uses: actions/download-artifact@v4
45+
with:
46+
name: python-package-distributions
47+
path: dist/
48+
- name: Publish distribution 📦 to PyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
51+
github-release:
52+
name: >-
53+
Sign the Python 🐍 distribution 📦 with Sigstore
54+
and upload them to GitHub Release
55+
needs:
56+
- publish-to-pypi
57+
runs-on: ubuntu-latest
58+
59+
permissions:
60+
contents: write # IMPORTANT: mandatory for making GitHub Releases
61+
id-token: write # IMPORTANT: mandatory for sigstore
62+
63+
steps:
64+
- name: Download all the dists
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: python-package-distributions
68+
path: dist/
69+
- name: Sign the dists with Sigstore
70+
uses: sigstore/[email protected]
71+
with:
72+
inputs: >-
73+
./dist/*.tar.gz
74+
./dist/*.whl
75+
- name: Create GitHub Release
76+
env:
77+
GITHUB_TOKEN: ${{ github.token }}
78+
run: gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --notes ""
79+
- name: Upload artifact signatures to GitHub Release
80+
env:
81+
GITHUB_TOKEN: ${{ github.token }}
82+
# Upload to GitHub Release using the `gh` CLI.
83+
# `dist/` contains the built packages, and the
84+
# sigstore-produced signatures and certificates.
85+
run: gh release upload "$GITHUB_REF_NAME" dist/** --repo "$GITHUB_REPOSITORY"
86+
87+
publish-to-testpypi:
88+
name: Publish Python 🐍 distribution 📦 to TestPyPI
89+
needs:
90+
- build
91+
runs-on: ubuntu-latest
92+
93+
environment:
94+
name: testpypi
95+
url: https://test.pypi.org/p/pyeleven
96+
97+
permissions:
98+
id-token: write # IMPORTANT: mandatory for trusted publishing
99+
100+
steps:
101+
- name: Download all the dists
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: python-package-distributions
105+
path: dist/
106+
- name: Publish distribution 📦 to TestPyPI
107+
uses: pypa/gh-action-pypi-publish@release/v1
108+
with:
109+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)