11import re
2+ import sys
3+ import os
24from pathlib import Path
35
46from praktika .info import Info
57from praktika .utils import Shell
68
9+ # NOTE(vnemkov): extrimely hackinsj, buts allows to reuse code from version_helper and git_helper with our modifications.
10+
11+ # allow to import other packages that are located in `tests/ci` directory, like `git_helper`
12+ import tests .ci
13+ sys .path .append (os .path .abspath (tests .ci .__path__ ._path [0 ]))
14+ from tests .ci .version_helper import (
15+ read_versions ,
16+ get_version_from_repo
17+ )
18+
19+ from tests .ci .git_helper import Git
20+
721
822class CHVersion :
923 FILE_WITH_VERSION_PATH = "./cmake/autogenerated_versions.txt"
@@ -23,66 +37,12 @@ class CHVersion:
2337
2438 @classmethod
2539 def get_release_version_as_dict (cls ):
26- versions = {}
27- for line in (
28- Path (cls .FILE_WITH_VERSION_PATH ).read_text (encoding = "utf-8" ).splitlines ()
29- ):
30- line = line .strip ()
31- if not line .startswith ("SET(" ):
32- continue
33-
34- name , value = line [4 :- 1 ].split (maxsplit = 1 )
35- name = name .removeprefix ("VERSION_" ).lower ()
36- if name in ("major" , "minor" , "patch" , "tweak" ):
37- value = int (value )
38- versions [name ] = value
39-
40- if versions .get ("flavour" ):
41- versions ["string" ] = f"{ versions ['string' ]} .{ versions ['flavour' ]} "
42-
43- result = {
44- "major" : versions ["major" ],
45- "minor" : versions ["minor" ],
46- "patch" : versions ["patch" ],
47- "revision" : versions ["revision" ],
48- "githash" : versions ["githash" ],
49- "describe" : versions ["describe" ],
50- "string" : versions ["string" ],
51- "tweak" : versions ["tweak" ],
52- "flavour" : versions .get ("flavour" , "" ),
53- }
54- return result
40+ return read_versions ()
5541
5642 @classmethod
5743 def get_current_version_as_dict (cls ):
58- version = cls .get_release_version_as_dict ()
59- info = Info ()
60- try :
61- tweak = int (
62- Shell .get_output (
63- f"git rev-list --count { version ['githash' ]} ..HEAD" , verbose = True
64- )
65- )
66- except ValueError :
67- # Shallow checkout
68- tweak = 1
69- version_type = "testing"
70- if info .pr_number == 0 and bool (
71- re .match (r"^\d{2}\.\d+$" , info .git_branch .removeprefix ("release/" ))
72- ):
73- if version ["minor" ] % 5 == 3 :
74- version_type = "lts"
75- else :
76- version_type = "stable"
77- version_string = (
78- f'{ version ["major" ]} .{ version ["minor" ]} .{ version ["patch" ]} .{ tweak } '
79- )
80- version_description = f"v{ version_string } -{ version_type } "
81- version ["githash" ] = info .sha
82- version ["tweak" ] = tweak
83- version ["describe" ] = version_description
84- version ["string" ] = version_string
85- return version
44+ git = Git ()
45+ return get_version_from_repo (CHVersion .FILE_WITH_VERSION_PATH , Git ()).as_dict ()
8646
8747 @classmethod
8848 def get_version (cls ):
@@ -102,3 +62,11 @@ def get_release_sha(cls):
10262 @classmethod
10363 def store_version_data_in_ci_pipeline (cls ):
10464 Info ().store_custom_data ("version" , cls .get_current_version_as_dict ())
65+ git = Git ()
66+ Info ().store_custom_data ("debug_version" , {
67+ "commits_since_latest" : git .commits_since_latest ,
68+ "commits_since_new" : git .commits_since_new ,
69+ "commits_since_upstream" : git .commits_since_upstream ,
70+ "latest_tag" : git .latest_tag ,
71+ "new_tag" : git .new_tag ,
72+ })
0 commit comments