Skip to content

Commit 9337eab

Browse files
committed
Add new publishing workflow.
1 parent 6964e78 commit 9337eab

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

.github/workflows/publish_pypi.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: publish-pypi
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
id-token: write
12+
13+
jobs:
14+
build-and-publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.12"
25+
26+
- name: Verify tag matches pyproject.toml version
27+
if: startsWith(github.ref, 'refs/tags/')
28+
run: |
29+
python - <<'PY'
30+
import os
31+
import tomllib
32+
33+
tag = os.environ["GITHUB_REF_NAME"]
34+
if not tag.startswith("v"):
35+
raise SystemExit(f"Tag must start with 'v', got {tag!r}")
36+
37+
tag_version = tag[1:]
38+
with open("pyproject.toml", "rb") as f:
39+
pyproject = tomllib.load(f)
40+
41+
project_version = pyproject["project"]["version"]
42+
if project_version != tag_version:
43+
raise SystemExit(
44+
f"Version mismatch: tag {tag_version} != pyproject.toml {project_version}"
45+
)
46+
47+
print(f"OK: {tag} matches pyproject.toml version {project_version}")
48+
PY
49+
50+
- name: Build distributions
51+
run: |
52+
python -m pip install -U pip build
53+
python -m build
54+
55+
- name: Check distributions
56+
run: |
57+
python -m pip install -U twine
58+
python -m twine check dist/*
59+
60+
- name: Publish to PyPI (Trusted Publishing)
61+
if: startsWith(github.ref, 'refs/tags/')
62+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)