Skip to content

Commit 2ac0f3e

Browse files
Add release guard checks and validate built artifacts
1 parent 1e9a10a commit 2ac0f3e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,30 @@ jobs:
2525
python -m pip install -U pip
2626
python -m pip install -U build
2727
python -m pip install -e ".[dev]"
28+
python -m pip install -U twine
2829
2930
- name: Run tests
3031
run: pytest -q
3132

3233
- name: Build sdist and wheel
3334
run: python -m build
3435

36+
- name: Twine check
37+
run: python -m twine check dist/*
38+
39+
- name: Version matches tag
40+
env:
41+
GITHUB_REF_NAME: ${{ github.ref_name }}
42+
run: python tools/version_guard.py --tag "$GITHUB_REF_NAME"
43+
44+
- name: Install wheel and import package
45+
run: |
46+
python -m pip install --force-reinstall dist/*.whl
47+
python - <<'PY'
48+
import sudoku_dlx as s
49+
print("import ok; version:", s.__version__)
50+
PY
51+
3552
- name: Upload artifacts
3653
uses: actions/upload-artifact@v4
3754
with:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ On pushing a tag like `v0.2.1`, GitHub Actions will:
181181
- build wheels/sdist, and
182182
- attach artifacts to the GitHub Release (no PyPI upload).
183183
184+
**Release gates**:
185+
- `twine check` validates the built metadata.
186+
- tag `vX.Y.Z` must equal `sudoku_dlx.__version__` (build fails if not).
187+
- installs the wheel and imports the package before attaching.
188+
184189
### Manual publish (when you’re ready)
185190
1. Create a token on PyPI (or TestPyPI).
186191
2. Add a repo secret:

tools/version_guard.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Fail the build if the Git tag (refs/tags/vX.Y.Z) does not match sudoku_dlx.__version__.
3+
Usage (CI): python tools/version_guard.py --tag "$GITHUB_REF_NAME"
4+
"""
5+
from __future__ import annotations
6+
import argparse, re, sys
7+
8+
def main() -> int:
9+
ap = argparse.ArgumentParser()
10+
ap.add_argument("--tag", required=True, help="git tag name, e.g. v0.2.1")
11+
ns = ap.parse_args()
12+
tag = ns.tag.strip()
13+
m = re.fullmatch(r"v(\d+\.\d+\.\d+)", tag)
14+
if not m:
15+
print(f"[version_guard] Not a release tag: {tag}", file=sys.stderr)
16+
return 2
17+
tag_ver = m.group(1)
18+
try:
19+
import sudoku_dlx as pkg
20+
except Exception as e:
21+
print(f"[version_guard] Failed to import sudoku_dlx: {e}", file=sys.stderr)
22+
return 3
23+
code_ver = getattr(pkg, "__version__", None)
24+
if code_ver is None:
25+
print("[version_guard] sudoku_dlx.__version__ missing", file=sys.stderr)
26+
return 4
27+
if code_ver != tag_ver:
28+
print(f"[version_guard] Version mismatch: tag v{tag_ver} != code {code_ver}", file=sys.stderr)
29+
return 5
30+
print(f"[version_guard] OK: tag v{tag_ver} == code {code_ver}")
31+
return 0
32+
33+
if __name__ == "__main__":
34+
raise SystemExit(main())

0 commit comments

Comments
 (0)