-
Notifications
You must be signed in to change notification settings - Fork 3
57 lines (46 loc) · 1.47 KB
/
pythonpublish.yml
File metadata and controls
57 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Upload Python Package to Pypi
on:
release:
types: [ published ]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Validate release tag and version (X.Y.Z and matches pyproject)
shell: bash
run: |
TAG="${{ github.event.release.tag_name }}"
echo "Release tag: $TAG"
if ! [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag must be X.Y.Z (e.g. 1.2.3). Got: $TAG"
exit 1
fi
- uses: actions/checkout@v4
- name: Validate pyproject.toml version matches tag
run: |
python - <<'PY'
import pathlib
import tomllib
tag = "${{ github.event.release.tag_name }}"
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text(encoding="utf-8"))
py_ver = data["project"]["version"]
print(f"pyproject.toml version: {py_ver}")
if py_ver != tag:
raise SystemExit(f"Version mismatch: tag={tag} but pyproject.toml={py_ver}")
PY
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Build distributions
run: |
python -m pip install --upgrade pip
pip install build
python -m build
- name: Publish to PyPI (OIDC)
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist