Fix: pre-commit and tox issues
[releng/builder.git] / scripts / bump_mri_versions / python_lib.py
1 # Copyright (c) 2023 PANTHEON.tech s.r.o. All rights reserved.
2 #
3 # This program and the accompanying materials are made available under the
4 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
5 # and is available at http://www.eclipse.org/legal/epl-v10.html
6
7 """Library calls for branch cutting a new stable release."""
8
9 # modify this dir for pick up project from there
10 bumping_dir = "repos"
11
12
13 def find_highest_revision(revisions):
14     """Return bigger versions in the tuple."""
15     # convert list of strings to list of tuples
16     converted_items = [tuple(map(int, item.split("."))) for item in revisions]
17     biggest_item = max(converted_items, key=lambda x: x)
18     biggest_version = ".".join(str(x) for x in biggest_item)
19     return biggest_version
20
21
22 def log_artifact(path, group_id=None, artifact_id=None, version=None, new_version=None):
23     """Add filename and path, artifactId, versions to log."""
24     log = ""
25     log += "XML FILE: " + str(path) + "\n"
26     # if none, printing feature update
27     if group_id is None:
28         log_line = ("path:", path, "VERSION:", version, "NEW VERSION:", new_version)
29     # else printing artifact update
30     else:
31         log_line = (
32             "groupId:",
33             group_id.text,
34             "ARTIFACT ID:",
35             artifact_id.text,
36             "VERSION:",
37             version,
38             "NEW VERSION:",
39             new_version,
40         )
41     log += str(log_line) + "\n"
42     log += str(100 * "*" + "\n")
43     return log
44
45
46 def check_minor_version(version, new_version):
47     """Take two version string and returns True if its same are the new version."""
48     # compares the corresponding elements of the two version strings
49     if any(
50         int(elem_a) != int(elem_b)
51         for elem_a, elem_b in zip(version.text.split("."), new_version.split("."))
52     ):
53         return True
54     return False