Skip to content

Commit 3633867

Browse files
fix: fix tag (#32)
1 parent fafa8b4 commit 3633867

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

scripts/check_version_match.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,62 @@
11
#!/usr/bin/env python3
2-
"""Check that pyproject version matches the latest git tag."""
2+
"""Check that pyproject version matches the latest git tag. Optionally fix it by tagging."""
33
from pathlib import Path
44
import subprocess
55
import sys
6+
67
if sys.version_info >= (3, 11):
78
import tomllib as tomli
89
else:
910
import tomli
1011

11-
1212
ROOT = Path(__file__).resolve().parents[1]
1313

14-
1514
def pyproject_version() -> str:
1615
pyproject_path = ROOT / "pyproject.toml"
1716
with pyproject_path.open("rb") as f:
1817
data = tomli.load(f)
1918
return data["tool"]["poetry"]["version"]
2019

21-
2220
def latest_tag() -> str:
2321
try:
2422
tag = subprocess.check_output(
2523
["git", "describe", "--tags", "--abbrev=0"], cwd=ROOT, text=True
2624
).strip()
2725
return tag.lstrip("v")
2826
except subprocess.CalledProcessError:
29-
return "0.0.0"
27+
return ""
3028

29+
def create_tag(version: str) -> None:
30+
print(f"Tagging repository with version: v{version}")
31+
subprocess.run(["git", "tag", f"v{version}"], cwd=ROOT, check=True)
32+
subprocess.run(["git", "push", "origin", f"v{version}"], cwd=ROOT, check=True)
33+
print(f"✅ Git tag v{version} created and pushed.")
3134

3235
def main() -> int:
33-
tag = latest_tag()
36+
fix = "--fix" in sys.argv
3437
version = pyproject_version()
38+
tag = latest_tag()
3539

3640
if not tag:
37-
print("No git tag found", file=sys.stderr)
38-
return 1
41+
print("⚠️ No git tag found.", file=sys.stderr)
42+
if fix:
43+
create_tag(version)
44+
return 0
45+
else:
46+
return 1
3947

4048
if version != tag:
4149
print(
42-
f"Version mismatch: pyproject.toml has {version} but latest tag is {tag}",
50+
f"Version mismatch: pyproject.toml has {version} but latest tag is {tag}",
4351
file=sys.stderr,
4452
)
53+
if fix:
54+
create_tag(version)
55+
return 0
4556
return 1
4657

47-
print(f"Version matches latest tag: {version}")
58+
print(f"✔️ Version matches latest tag: {version}")
4859
return 0
4960

50-
5161
if __name__ == "__main__":
5262
sys.exit(main())

0 commit comments

Comments
 (0)