diff --git a/tests/ci/docker_test.py b/tests/ci/docker_test.py index 9d68f4364391..d5d27f73694a 100644 --- a/tests/ci/docker_test.py +++ b/tests/ci/docker_test.py @@ -10,9 +10,8 @@ from report import TestResult import docker_images_check as di -with patch("git_helper.Git"): - from version_helper import get_version_from_string - import docker_server as ds +from version_helper import get_version_from_string +import docker_server as ds # di.logging.basicConfig(level=di.logging.INFO) @@ -312,7 +311,3 @@ def test_auto_release_type(self, mock_tagged_versions: MagicMock) -> None: for case in cases_equal: release = ds.auto_release_type(case[0], "auto") self.assertEqual(case[1], release) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/ci/git_helper.py b/tests/ci/git_helper.py index eb5e835eab3d..ab1caa426605 100644 --- a/tests/ci/git_helper.py +++ b/tests/ci/git_helper.py @@ -126,15 +126,16 @@ def update(self): # Format should match TAG_REGEXP if self._ignore_no_tags and is_shallow(): try: - self._update_tags() + self._update_tags(True) except subprocess.CalledProcessError: pass return self._update_tags() - def _update_tags(self): - self.latest_tag = self.run("git describe --tags --abbrev=0") + def _update_tags(self, suppress_stderr: bool = False) -> None: + stderr = subprocess.DEVNULL if suppress_stderr else None + self.latest_tag = self.run("git describe --tags --abbrev=0", stderr=stderr) # Format should be: {latest_tag}-{commits_since_tag}-g{sha_short} self.description = self.run("git describe --tags --long") self.commits_since_tag = int( @@ -171,7 +172,16 @@ def tweak(self) -> int: if not self.latest_tag.endswith("-testing"): # When we are on the tag, we still need to have tweak=1 to not # break cmake with versions like 12.13.14.0 - return self.commits_since_tag or TWEAK + if not self.commits_since_tag: + # We are in a tagged commit. The tweak should match the + # current version's value + version = self.latest_tag.split("-", maxsplit=1)[0] + try: + return int(version.split(".")[-1]) + except ValueError: + # There are no tags, or a wrong tag. Return default + return TWEAK + return self.commits_since_tag version = self.latest_tag.split("-", maxsplit=1)[0] return int(version.split(".")[-1]) + self.commits_since_tag diff --git a/tests/ci/version_helper.py b/tests/ci/version_helper.py index 372974f4eda8..15229c3d21dd 100755 --- a/tests/ci/version_helper.py +++ b/tests/ci/version_helper.py @@ -335,6 +335,7 @@ def main(): "--version-type", "-t", choices=VersionType.VALID, + default=VersionType.TESTING, help="optional parameter to generate DESCRIBE", ) parser.add_argument( @@ -344,10 +345,16 @@ def main(): help="if the ENV variables should be exported", ) parser.add_argument( - "--update", - "-u", + "--update-part", choices=("major", "minor", "patch"), - help="the version part to update, tweak is always calculated from commits", + help="the version part to update, tweak is always calculated from commits, " + "implies `--update-cmake`", + ) + parser.add_argument( + "--update-cmake", + "-u", + action="store_true", + help=f"is update for {FILE_WITH_VERSION_PATH} is needed or not", ) parser.add_argument( "--update-contributors", @@ -364,13 +371,12 @@ def main(): version = get_version_from_repo(args.version_path, Git(True)) - if args.update: - version = version.update(args.update) + if args.update_part: + version = version.update(args.update_part) - if args.version_type: - version.with_description(args.version_type) + version.with_description(args.version_type) - if args.update: + if args.update_part or args.update_cmake: update_cmake_version(version) for k, v in version.as_dict().items(): diff --git a/tests/ci/version_test.py b/tests/ci/version_test.py index abd0f9349f4b..978edcc093ec 100644 --- a/tests/ci/version_test.py +++ b/tests/ci/version_test.py @@ -11,11 +11,11 @@ def test_version_arg(self): cases = ( ("0.0.0.0", vh.get_version_from_string("0.0.0.0")), ("1.1.1.2", vh.get_version_from_string("1.1.1.2")), - ("v1.1.1.2-lts", vh.get_version_from_string("1.1.1.2")), - ("v1.1.1.2-prestable", vh.get_version_from_string("1.1.1.2")), - ("v1.1.1.2-stable", vh.get_version_from_string("1.1.1.2")), - ("v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")), - ("refs/tags/v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")), + ("v11.1.1.2-lts", vh.get_version_from_string("11.1.1.2")), + ("v01.1.1.2-prestable", vh.get_version_from_string("1.1.1.2")), + ("v21.1.1.2-stable", vh.get_version_from_string("21.1.1.2")), + ("v31.1.1.2-testing", vh.get_version_from_string("31.1.1.2")), + ("refs/tags/v31.1.1.2-testing", vh.get_version_from_string("31.1.1.2")), ) for test_case in cases: version = vh.version_arg(test_case[0]) @@ -25,6 +25,7 @@ def test_version_arg(self): "1.1.1.a", "1.1.1.1.1", "1.1.1.2-testing", + "v1.1.1.2-testing", "v1.1.1.2-testin", "refs/tags/v1.1.1.2-testin", )