2023-07-28 02:30:16 +02:00
|
|
|
import argparse
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
from dataclasses import dataclass
|
2023-10-04 00:45:23 +02:00
|
|
|
from pathlib import Path
|
2023-07-28 02:30:16 +02:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Version:
|
|
|
|
major: int
|
|
|
|
minor: int
|
|
|
|
patch: int
|
|
|
|
extra: str
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"{self.major}.{self.minor}.{self.patch}{self.extra}"
|
|
|
|
|
|
|
|
def parse_version(text: str) -> Version:
|
2024-01-07 03:59:54 +01:00
|
|
|
if (match := re.fullmatch(r"(\d+)\.(\d+).(\d+)(.*)", text)):
|
2023-07-28 02:30:16 +02:00
|
|
|
return Version(
|
|
|
|
major=int(match.group(1)),
|
|
|
|
minor=int(match.group(2)),
|
|
|
|
patch=int(match.group(3)),
|
|
|
|
extra=match.group(4)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
raise ValueError(f"Couldn't parse {text} as a version number")
|
|
|
|
|
2023-10-04 00:45:23 +02:00
|
|
|
def rewrite_debian_control_file():
|
2024-01-07 03:59:54 +01:00
|
|
|
path = Path(__file__).parents[1] / "packaging/debian/f.e.i.s-control"
|
2023-10-04 00:45:23 +02:00
|
|
|
with path.open(mode="r+") as f:
|
|
|
|
debian_control_lines = f.readlines()
|
|
|
|
for i in range(len(debian_control_lines)):
|
|
|
|
line = debian_control_lines[i]
|
|
|
|
if line.startswith("Version:"):
|
|
|
|
debian_control_lines[i] = f"Version: {args.version}\n"
|
|
|
|
|
|
|
|
f.truncate(0)
|
|
|
|
f.seek(0)
|
|
|
|
f.writelines(debian_control_lines)
|
|
|
|
|
2023-07-28 02:30:16 +02:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("version", type=parse_version)
|
2023-10-04 00:47:06 +02:00
|
|
|
parser.add_argument("--dry-run", action="store_true")
|
2023-07-28 02:30:16 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-10-04 00:45:23 +02:00
|
|
|
rewrite_debian_control_file()
|
2023-07-28 02:30:16 +02:00
|
|
|
subprocess.check_call(["meson", "rewrite", "kwargs", "set", "project", "/", "version", str(args.version)])
|
2023-10-04 00:47:06 +02:00
|
|
|
if not args.dry_run:
|
2024-01-07 03:59:54 +01:00
|
|
|
subprocess.check_call(["git", "add", "meson.build", "packaging/debian/f.e.i.s-control"])
|
2023-10-04 00:47:06 +02:00
|
|
|
subprocess.check_call(["git", "commit", "-m", f"bump to v{args.version}"])
|
|
|
|
subprocess.check_call(["git", "tag", f"v{args.version}"])
|