Fix a versions' tweak for tagged commits, improve version_helper

This commit is contained in:
Mikhail f. Shiryaev 2023-06-15 14:05:01 +02:00
parent c15e7b93cb
commit 07203a4542
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 24 additions and 9 deletions

View File

@ -171,7 +171,16 @@ class Git:
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

View File

@ -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)
if args.update:
if args.update_part or args.update_cmake:
update_cmake_version(version)
for k, v in version.as_dict().items():