Merge "Feat: add a script to script/bump_mri_versions"
[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 # modify this dir for pick up project from there
8 bumping_dir = "repos"
9
10
11 def find_highest_revision(revisions):
12     # convert list of strings to list of tuples
13     converted_items = [tuple(map(int, item.split('.'))) for item in revisions]
14     biggest_item = max(converted_items, key=lambda x: x)
15     biggest_version = '.'.join(str(x) for x in biggest_item)
16     return biggest_version
17
18
19 def log_artifact(path, group_id=None, artifact_id=None, version=None, new_version=None):
20     log = ""
21     log += "XML FILE: " + str(path) + "\n"
22     # if none, printing feature update
23     if group_id is None:
24         log_line = ("path:", path, "VERSION:", version,
25                     "NEW VERSION:", new_version)
26     # else printing artifact update
27     else:
28         log_line = ("groupId:", group_id.text, "ARTIFACT ID:",
29                     artifact_id.text, "VERSION:", version, "NEW VERSION:", new_version)
30     log += str(log_line) + "\n"
31     log += str(100 * "*" + "\n")
32     return log
33
34
35 def check_minor_version(version, new_version):
36     # compares the corresponding elements of the two version strings
37     if any(int(elem_a) != int(elem_b) for elem_a, elem_b in zip(version.text.split("."), new_version.split("."))):
38         return True
39     return False