add version bumping

This commit is contained in:
Jev Kuznetsov
2026-04-23 10:48:10 +02:00
parent cbc6cde693
commit 9a5bd2c0d4
+37
View File
@@ -1,6 +1,11 @@
# type: ignore # type: ignore
import re
from pathlib import Path
from invoke import task from invoke import task
PYPROJECT = Path(__file__).parent / "pyproject.toml"
@task @task
def venv(c): def venv(c):
@@ -42,6 +47,38 @@ def ci(c):
c.run(f"docker run --rm {image} sh -c '{cmd}'") c.run(f"docker run --rm {image} sh -c '{cmd}'")
@task
def bump(c, part):
"""Bump version (patch/minor/major), commit, and tag."""
if part not in ("patch", "minor", "major"):
raise SystemExit("Usage: inv bump <patch|minor|major>")
result = c.run("git status --porcelain", hide=True)
if result.stdout.strip():
raise SystemExit("Working tree is dirty. Commit or stash changes first.")
text = PYPROJECT.read_text()
m = re.search(r'version = "(\d+)\.(\d+)\.(\d+)"', text)
if not m:
raise SystemExit("Could not find version in pyproject.toml")
major, minor, patch = int(m[1]), int(m[2]), int(m[3])
if part == "major":
major, minor, patch = major + 1, 0, 0
elif part == "minor":
minor, patch = minor + 1, 0
else:
patch += 1
new_version = f"{major}.{minor}.{patch}"
new_text = re.sub(r'(version = ")\d+\.\d+\.\d+(")', rf"\g<1>{new_version}\2", text)
PYPROJECT.write_text(new_text)
c.run(f'git add pyproject.toml && git commit -m "bump version to {new_version}"')
c.run(f"git tag v{new_version}")
print(f"Bumped to {new_version}")
@task @task
def clean(c): def clean(c):
"""Preview files to delete (safe mode).""" """Preview files to delete (safe mode)."""