Skip to content

Commit 1123ff6

Browse files
committed
CI: Stage release packages to PyPI through GHA
1 parent e9f6280 commit 1123ff6

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/workflows/release-pypi.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Stage Python source distribution and wheel packages through GitHub Actions (GHA) to Python Package Index (PyPI).
2+
name: "Release: Python package"
3+
4+
on:
5+
6+
# Build and publish packages when running a release.
7+
push:
8+
tags:
9+
- '*'
10+
11+
# Build packages on each pull request for validation purposes.
12+
pull_request:
13+
14+
# Build packages each night for validation purposes.
15+
schedule:
16+
- cron: '0 4 * * *'
17+
18+
# Allow the job to be triggered manually.
19+
workflow_dispatch:
20+
21+
jobs:
22+
build-and-publish:
23+
name: "Build and publish to PyPI"
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
os: ["ubuntu-latest"]
29+
python-version: ["3.13"]
30+
env:
31+
OS_TYPE: ${{ matrix.os }}
32+
PYTHON_VERSION: ${{ matrix.python-version }}
33+
UV_SYSTEM_PYTHON: true
34+
35+
# Trusted publishing.
36+
# Specifying a GitHub environment is optional, but strongly encouraged
37+
environment: pypi
38+
permissions:
39+
# IMPORTANT: this permission is mandatory for Trusted Publishing
40+
id-token: write
41+
42+
steps:
43+
- name: Acquire sources
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
51+
- name: Set up uv
52+
uses: astral-sh/setup-uv@v6
53+
with:
54+
cache-dependency-glob: |
55+
setup.py
56+
pyproject.toml
57+
cache-suffix: ${{ matrix.python-version }}
58+
enable-cache: true
59+
version: "latest"
60+
61+
- name: Build package
62+
run: |
63+
uv pip install build
64+
python -m build
65+
66+
- name: Publish package to PyPI
67+
if: startsWith(github.event.ref, 'refs/tags')
68+
uses: pypa/gh-action-pypi-publish@release/v1

docs/release.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Release
2+
3+
Building Python packages and publishing to PyPI is automated
4+
using the GHA workflow `release-pypi.yml`.
5+
6+
To release the package, exercise those steps:
7+
8+
- Edit `CHANGELOG.md`, designating a new version. Commit the file
9+
using a commit message like `Release 4.1.1`.
10+
11+
- Create a tag using the new version, including a `v` prefix, e.g.
12+
```shell
13+
git tag v4.1.1
14+
```
15+
16+
- Push to remote.
17+
```shell
18+
git push --follow-tags
19+
```

0 commit comments

Comments
 (0)