Skip to content

Commit 443fb4b

Browse files
committed
Add GitHub Action to publish witwin to PyPI
Adds a workflow that publishes the witwin package to PyPI on published releases with tags of the form 'witwin-v<version>' (excluding prereleases). It locates pyproject.toml in the repo root or core/, validates the release tag matches the package name and version, builds distributions using Python 3.11, and uploads them via pypa/gh-action-pypi-publish. This enforces tag/version consistency and automates PyPI releases.
1 parent 5e736c7 commit 443fb4b

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish witwin
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
if: startsWith(github.event.release.tag_name, 'witwin-v') && !github.event.release.prerelease
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
environment:
15+
name: pypi
16+
url: https://pypi.org/project/witwin/
17+
18+
steps:
19+
- name: Check out repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
27+
- name: Resolve package directory
28+
id: package_dir
29+
shell: bash
30+
run: |
31+
if [ -f pyproject.toml ]; then
32+
echo "path=." >> "$GITHUB_OUTPUT"
33+
elif [ -f core/pyproject.toml ]; then
34+
echo "path=core" >> "$GITHUB_OUTPUT"
35+
else
36+
echo "Unable to find pyproject.toml for the witwin package." >&2
37+
exit 1
38+
fi
39+
40+
- name: Validate release tag and package version
41+
shell: bash
42+
env:
43+
PACKAGE_DIR: ${{ steps.package_dir.outputs.path }}
44+
RELEASE_TAG: ${{ github.event.release.tag_name }}
45+
run: |
46+
python - <<'PY'
47+
import os
48+
import re
49+
import sys
50+
import tomllib
51+
from pathlib import Path
52+
53+
tag = os.environ["RELEASE_TAG"]
54+
match = re.fullmatch(r"witwin-v(?P<version>[0-9A-Za-z.+_-]+)", tag)
55+
if match is None:
56+
print(f"Release tag '{tag}' must match 'witwin-v<version>'.", file=sys.stderr)
57+
raise SystemExit(1)
58+
59+
expected_version = match.group("version")
60+
pyproject_path = Path(os.environ["PACKAGE_DIR"]) / "pyproject.toml"
61+
data = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
62+
63+
project = data["project"]
64+
package_name = project["name"]
65+
package_version = project["version"]
66+
67+
if package_name != "witwin":
68+
print(f"Expected package name 'witwin', found '{package_name}'.", file=sys.stderr)
69+
raise SystemExit(1)
70+
71+
if package_version != expected_version:
72+
print(
73+
f"Release tag version '{expected_version}' does not match pyproject version '{package_version}'.",
74+
file=sys.stderr,
75+
)
76+
raise SystemExit(1)
77+
78+
print(f"Validated {package_name} {package_version} from {pyproject_path}.")
79+
PY
80+
81+
- name: Build distributions
82+
shell: bash
83+
env:
84+
PACKAGE_DIR: ${{ steps.package_dir.outputs.path }}
85+
run: |
86+
python -m pip install --upgrade pip build
87+
python -m build "$PACKAGE_DIR"
88+
89+
- name: Publish distributions to PyPI
90+
uses: pypa/gh-action-pypi-publish@release/v1
91+
with:
92+
packages-dir: ${{ steps.package_dir.outputs.path }}/dist

0 commit comments

Comments
 (0)