Skip to content

Commit

Permalink
Get latest version in CD via Python script (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedTwigleg authored Jan 27, 2023
1 parent 4673f3b commit dfd24e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion utils/publish-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pushd $(dirname $0) > /dev/null

# Get the current version
git checkout main
current_version=$(git describe --tags --abbrev=0)

git_tags=$(git tag)
current_version=$(python3 ./update_semantic_version.py --version "${git_tags}" --type MINOR --parse_latest_version true)
current_version_without_v=$(echo ${current_version} | cut -f2 -dv)

echo "Current release version is ${current_version_without_v}"
Expand Down
38 changes: 38 additions & 0 deletions utils/update_semantic_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,46 @@ def main():
required=True, help="The version string to update")
argument_parser.add_argument("--type", metavar="<string containing PATCH, MINOR, or MAJOR>",
required=True, help="Which version number to bump")
argument_parser.add_argument("--parse_latest_version", metavar="<true>",
help="Takes '$(git tag)' and returns the highest version in the list", default="false")
parsed_commands = argument_parser.parse_args()

if (parsed_commands.parse_latest_version == "true"):
version_list = parsed_commands.version.split("\n")
highest = [0, 0, 0]

for i in range(0, len(version_list)):
i_version = version_list[i]
i_version = i_version.replace("v", "")

i_version_tuple = i_version.split(".")
if (len(i_version_tuple) != 3):
continue

i_version_tuple[0] = int(i_version_tuple[0])
i_version_tuple[1] = int(i_version_tuple[1])
i_version_tuple[2] = int(i_version_tuple[2])

if (highest == None):
highest = i_version_tuple
continue
else:
if (i_version_tuple[0] > highest[0]):
highest = i_version_tuple
continue
if (i_version_tuple[0] >= highest[0] and i_version_tuple[1] > highest[1]):
highest = i_version_tuple
continue
if (i_version_tuple[0] >= highest[0] and i_version_tuple[1] >= highest[1] and i_version_tuple[2] >= highest[2]):
highest = i_version_tuple
continue

if (highest[0] != 0 and highest[1] != 0 and highest[2] != 0):
print(f"v{highest[0]}.{highest[1]}.{highest[2]}")
sys.exit(0)
else:
sys.exit(-1)

version_tuple = parsed_commands.version.split(".")
if len(version_tuple) != 3:
print("0.0.0") # Error
Expand Down

0 comments on commit dfd24e4

Please sign in to comment.