Skip to content

Commit 25ac10f

Browse files
authored
Pypi publishing GH action (#9)
1 parent 890db58 commit 25ac10f

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

.github/workflows/pypi.yml

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

0 commit comments

Comments
 (0)