From 946874ee7b8c2105bdcefbe3e5101c00e931936b Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Wed, 26 May 2021 20:45:43 +0200 Subject: [PATCH] Initial commit --- latest-tags.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 latest-tags.py diff --git a/latest-tags.py b/latest-tags.py new file mode 100755 index 0000000..02fc10b --- /dev/null +++ b/latest-tags.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# +# Script for retrieving the git tags in truly chronological order. +# +# 2021 (c) Marcel Kapfer +# Licensed under the MIT/Expat License +# +# NOTES: +# +# - This is a draft! It may burn your house, delete your harddrive +# and/or kill your kitten. +# +# ISSUES: +# +# - There are some repos who maintain different major versions over +# some time in specific branches and that the release not on +# master/main/whatever but on these version branches. This may +# result in issues when using the sorting of tags retrieved by this +# script somewhere else. + +import subprocess + + +def main(): + # TODO: Add user defined keywords to the list. + ignored_keywords = ["pre", "rc", "beta", "alpha", "dev"] + # TODO: Add a ability for the user to customize this. + default_branch = "master" + + # Retrieve all tags in the repo (that are fetched...) + tags = subprocess.run(["git", "tag"], stdout=subprocess.PIPE) + allowedTags = {} + for tag in tags.stdout.decode('utf-8').splitlines(): + # Sort out tags that contain any `ignored_keywords` + if len([ignored_keyword for ignored_keyword in ignored_keywords if ignored_keyword in tag]) != 0: + continue + # Retriev the date in ISO-8061 format from git + date = subprocess.run(["git", "log", "-1", "--format='%aI'", tag], stdout=subprocess.PIPE) + # Strip away the encloding quotes as well as some whitespace + allowedTags[tag] = date.stdout.decode('utf-8').strip(" \n'") + # Sort by keys, which are the retrieved timestampes + allowedTags = sorted(allowedTags.items(), key=lambda item: item[1]) + + # Printing out + for k,v in allowedTags: + print(k) + print("Latest tag: {}\nSecond latest tag: {}".format(allowedTags[-1][0],allowedTags[-2][0])) + + +if __name__ == "__main__": + main()