Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a versions' tweak for tagged commits, improve version_helper #51035

Merged
merged 3 commits into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions tests/ci/docker_test.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
18 changes: 14 additions & 4 deletions tests/ci/git_helper.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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
22 changes: 14 additions & 8 deletions tests/ci/version_helper.py
Expand Up @@ -335,6 +335,7 @@ def main():
"--version-type",
"-t",
choices=VersionType.VALID,
default=VersionType.TESTING,
help="optional parameter to generate DESCRIBE",
)
parser.add_argument(
Expand All @@ -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",
Expand All @@ -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():
Expand Down
11 changes: 6 additions & 5 deletions tests/ci/version_test.py
Expand Up @@ -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])
Expand All @@ -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",
)
Expand Down