ClickHouse/ci/jobs/scripts/clickhouse_version.py
2024-11-20 21:10:35 +01:00

37 lines
1.1 KiB
Python

from pathlib import Path
from praktika.utils import Shell
class CHVersion:
FILE_WITH_VERSION_PATH = "./cmake/autogenerated_versions.txt"
@classmethod
def _get_tweak(cls):
tag = Shell.get_output("git describe --tags --abbrev=0")
assert tag.startswith("v24")
num = Shell.get_output(f"git rev-list --count {tag}..HEAD")
return int(num)
@classmethod
def get_version(cls):
versions = {}
for line in (
Path(cls.FILE_WITH_VERSION_PATH).read_text(encoding="utf-8").splitlines()
):
line = line.strip()
if not line.startswith("SET("):
continue
name, value = line[4:-1].split(maxsplit=1)
name = name.removeprefix("VERSION_").lower()
try:
value = int(value)
except ValueError:
pass
versions[name] = value
version_sha = versions["githash"]
tweak = int(Shell.get_output(f"git rev-list --count {version_sha}..HEAD", verbose=True))
return f"{versions['major']}.{versions['minor']}.{versions['patch']}.{tweak}"