viv/scripts/release.py

61 lines
1.4 KiB
Python
Raw Permalink Normal View History

2023-08-23 02:35:05 -05:00
#!/usr/bin/env python3
import re
import subprocess
import sys
from datetime import datetime
from pathlib import Path
FILE = Path(__file__).parent.parent / "src/viv/viv.py"
def get_version():
return subprocess.check_output(
[
"git",
"describe",
"--tags",
"--always",
"--dirty=-dev",
"--exclude",
"latest",
],
text=True,
)
def inc_build(build):
"""increment build number while keeping lexicographic order
1001 -> 1002
1999 -> 22000
22001 -> 22002
"""
next = str(int(build) + 1)
return next if build[0] <= next[0] else f"{int(next[0])*11}{next[1:]}"
def release():
full = get_version()
if full.endswith("-dev"):
print("uncommitted changes refusing to proceed")
sys.exit(1)
# remove v and git info
current = full[1:].split("-")[0]
_, build = current.split(".")
next = f"{datetime.now().year}.{inc_build(build)}"
msg = f"bump {current} -> {next}"
FILE.write_text(
2023-09-21 14:50:46 -05:00
re.sub(r'__version__ = ".*"', f'__version__ = "{next}"', FILE.read_text())
2023-08-23 02:35:05 -05:00
)
subprocess.run(["git", "add", FILE])
subprocess.run(["git", "commit", "-m", msg, "--no-verify"])
subprocess.run(["git", "tag", f"v{next}"])
2023-09-21 14:50:46 -05:00
FILE.write_text(
re.sub(r'__version__ = ".*"', f'__version__ = "{next}-dev"', FILE.read_text())
)
2023-08-23 02:35:05 -05:00
if __name__ == "__main__":
release()