Skip to content

Commit f88a7ce

Browse files
committed
Add Github release workflow
1 parent 99b4e67 commit f88a7ce

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)