From 6e0f358fbe194fbf8a7ef3aa6a617da291125309 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 22 Aug 2026 20:09:28 +0300 Subject: [PATCH] moving to bump.py --- .bumpversion.cfg | 39 ---------------------- Makefile | 2 +- bump.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 40 deletions(-) delete mode 100644 .bumpversion.cfg create mode 100755 bump.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index 032cdd9..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,39 +0,0 @@ -[bumpversion] -commit = True -tag = True -current_version = 6.62 -parse = (?P\d+)\.(?P\d+) -serialize = - {major}.{minor} - -[bumpversion:file:src/libs/const.h] -parse = (?P\d+) -serialize = {major} -search = VERSION_MAJOR {current_version} -replace = VERSION_MAJOR {new_version} - -[bumpversion:file:./src/libs/const.h] -parse = \d+\.(?P\d+) -serialize = {minor} -search = VERSION_MINOR {current_version} -replace = VERSION_MINOR {new_version} - -[bumpversion:file:python/setup.py] -search = version="{current_version}" -replace = version="{new_version}" - -[bumpversion:file:pkg/arch/PKGBUILD] -search = pkgver={current_version} -replace = pkgver={new_version} - -[bumpversion:file:pkg/openwrt/Makefile] -search = PKG_VERSION:={current_version} -replace = PKG_VERSION:={new_version} - -[bumpversion:file:man/ustreamer.1] -search = "version {current_version}" -replace = "version {new_version}" - -[bumpversion:file:man/ustreamer-dump.1] -search = "version {current_version}" -replace = "version {new_version}" diff --git a/Makefile b/Makefile index 9a99bdc..7a8bd89 100644 --- a/Makefile +++ b/Makefile @@ -132,7 +132,7 @@ linters: bump: - bumpversion $(if $(V),$(V),minor) + ./bump.py $(if $(V),$(V),minor) push: diff --git a/bump.py b/bump.py new file mode 100755 index 0000000..38a4309 --- /dev/null +++ b/bump.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# ========================================================================== # +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2024 Maxim Devaev # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# ========================================================================== # + + +import sys +import os +import re +import subprocess + + +# ===== +def _run(cmd: list[str]) -> str: + return str(subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode()) + + +def _get_version() -> tuple[int, int]: + ver = _run(["/usr/bin/git", "describe", "--tags", "--abbrev=0"]).strip() + assert (m := re.match(r"v(\d+)\.(\d+)", ver)), ver + return (int(m.group(1)), int(m.group(2))) + + +def _make_version(major: int, minor: int) -> str: + return f"v{major}.{minor}" + + +def _patch_file(path: str, replace: str, old: tuple[int, int], new: tuple[int, int]) -> None: + with open(path, "r+") as f: + old_text = f.read() + new_text = old_text.replace( + replace.format(major=old[0], minor=old[1]), + replace.format(major=new[0], minor=new[1]), + ) + # assert old_text != new_text, path + f.seek(0, os.SEEK_SET) + f.write(new_text) + + +def _bump(do_major: bool, items: list[tuple[str, str]]) -> None: + _run(["/usr/bin/git", "diff-index", "--quiet", "HEAD", "--"]) + + old = _get_version() + new = ((old[0] + 1, old[1]) if do_major else (old[0], old[1] + 1)) + + for (path, replace) in items: + _patch_file(path, replace, old, new) + _run(["/usr/bin/git", "add", path]) + + ver_new = _make_version(*new) + _run(["/usr/bin/git", "commit", "-m", f"Bump version: {_make_version(*old)} -> {ver_new}"]) + _run(["/usr/bin/git", "tag", ver_new]) + + +# ===== +if __name__ == "__main__": + _bump( + do_major=(len(sys.argv) == 2 and sys.argv[1] == "major"), + items=[ + ("src/libs/const.h", "define US_VERSION_MAJOR {major}"), + ("src/libs/const.h", "define US_VERSION_MINOR {minor}"), + ("python/setup.py", "version=\"{major}.{minor}\""), + ("man/ustreamer.1", "version {major}.{minor}"), + ("man/ustreamer-dump.1", "version {major}.{minor}"), + ("pkg/arch/PKGBUILD", "pkgver={major}.{minor}"), + ("pkg/openwrt/Makefile", "PKG_VERSION:={major}.{minor}"), + ], + )