From 93b2ac1ea1f541c55ecb36f6425ae99267b90d2a Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Wed, 11 Sep 2024 16:05:01 +0200 Subject: [PATCH] Update nix/flake.nix when a new version is released --- tasks.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tasks.py b/tasks.py index 2ccf8e2..4ab252a 100644 --- a/tasks.py +++ b/tasks.py @@ -62,16 +62,30 @@ def create_pr(c, skip_changelog=False): cerun(c, "gh pr merge --auto -dm") +def replace_in_file(path, rx, replacement): + text = path.read_text() + text, count = rx.subn(replacement, text) + if count == 0: + # Can happen if a command has to be re-run another time + return + if count > 1: + sys.exit(f"Too many replacements in {path}: {count}") + path.write_text(text) + + @task def update_version(c): version = get_version() - path = Path("CMakeLists.txt") - text = path.read_text() - text, count = re.subn( - r"^ VERSION .*", f' VERSION {version}', text, flags=re.MULTILINE + replace_in_file( + Path("CMakeLists.txt"), + re.compile(r"^ VERSION .*", flags=re.MULTILINE), + f" VERSION {version}" + ) + replace_in_file( + Path("nix/flake.nix"), + re.compile(r'version = "\d+\.\d+\.\d+";'), + f'version = "{version}";' ) - assert count == 0 or count == 1 - path.write_text(text) @task