Skip to content

Commit 4fb393a

Browse files
Get latest version in CD via Python script (#528)
1 parent a219711 commit 4fb393a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

utils/publish-release.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ pushd $(dirname $0) > /dev/null
1818

1919
# Get the current version
2020
git checkout main
21-
current_version=$(git describe --tags --abbrev=0)
21+
22+
git_tags=$(git tag)
23+
current_version=$(python3 ./update_semantic_version.py --version "${git_tags}" --type MINOR --parse_latest_version true)
2224
current_version_without_v=$(echo ${current_version} | cut -f2 -dv)
2325

2426
echo "Current release version is ${current_version_without_v}"

utils/update_semantic_version.py

+38
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,46 @@ def main():
1212
required=True, help="The version string to update")
1313
argument_parser.add_argument("--type", metavar="<string containing PATCH, MINOR, or MAJOR>",
1414
required=True, help="Which version number to bump")
15+
argument_parser.add_argument("--parse_latest_version", metavar="<true>",
16+
help="Takes '$(git tag)' and returns the highest version in the list", default="false")
1517
parsed_commands = argument_parser.parse_args()
1618

19+
if (parsed_commands.parse_latest_version == "true"):
20+
version_list = parsed_commands.version.split("\n")
21+
highest = [0, 0, 0]
22+
23+
for i in range(0, len(version_list)):
24+
i_version = version_list[i]
25+
i_version = i_version.replace("v", "")
26+
27+
i_version_tuple = i_version.split(".")
28+
if (len(i_version_tuple) != 3):
29+
continue
30+
31+
i_version_tuple[0] = int(i_version_tuple[0])
32+
i_version_tuple[1] = int(i_version_tuple[1])
33+
i_version_tuple[2] = int(i_version_tuple[2])
34+
35+
if (highest == None):
36+
highest = i_version_tuple
37+
continue
38+
else:
39+
if (i_version_tuple[0] > highest[0]):
40+
highest = i_version_tuple
41+
continue
42+
if (i_version_tuple[0] >= highest[0] and i_version_tuple[1] > highest[1]):
43+
highest = i_version_tuple
44+
continue
45+
if (i_version_tuple[0] >= highest[0] and i_version_tuple[1] >= highest[1] and i_version_tuple[2] >= highest[2]):
46+
highest = i_version_tuple
47+
continue
48+
49+
if (highest[0] != 0 and highest[1] != 0 and highest[2] != 0):
50+
print(f"v{highest[0]}.{highest[1]}.{highest[2]}")
51+
sys.exit(0)
52+
else:
53+
sys.exit(-1)
54+
1755
version_tuple = parsed_commands.version.split(".")
1856
if len(version_tuple) != 3:
1957
print("0.0.0") # Error

0 commit comments

Comments
 (0)