Skip to content

Commit 5287fce

Browse files
committed
Add a PyPI publish workflow
1 parent 174b847 commit 5287fce

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/publish.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Publish to PyPI / GitHub
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
11+
env:
12+
PYTHON_VERSION: "3.14"
13+
14+
jobs:
15+
build:
16+
name: "Build the project"
17+
runs-on: ubuntu-latest
18+
19+
outputs:
20+
prerelease: ${{ steps.check-version.outputs.prerelease }}
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup uv
27+
uses: astral-sh/setup-uv@v5
28+
with:
29+
version: "latest"
30+
python-version: ${{ env.PYTHON_VERSION }}
31+
enable-cache: true
32+
cache-suffix: "publish-py${{ env.python-version }}"
33+
34+
- name: Install dependencies
35+
run: |
36+
# We only need the project dependencies, no development deps
37+
uv sync --no-default-groups
38+
39+
- name: Upload build files
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: "dist"
43+
path: "dist/"
44+
if-no-files-found: error
45+
retention-days: 5
46+
47+
publish-github:
48+
name: "Publish a GitHub release"
49+
needs: build
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- name: Download the distribution files from PR artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: "dist"
57+
path: "dist/"
58+
59+
- name: Create Release
60+
uses: ncipollo/release-action@v1
61+
with:
62+
artifacts: "dist/*"
63+
bodyFile: changelog.txt
64+
draft: false
65+
66+
publish-pypi:
67+
name: "Publish to PyPI"
68+
needs: build
69+
runs-on: ubuntu-latest
70+
permissions:
71+
# Used to authenticate to PyPI via OIDC.
72+
id-token: write
73+
74+
steps:
75+
- name: Download the distribution files from PR artifact
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: "dist"
79+
path: "dist/"
80+
81+
# This uses PyPI's trusted publishing, so no token is required
82+
- name: Release to PyPI
83+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)