improve the git describe command

- When using the [action versioning recommendations](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations), a commit can have duplicate tags (v2, v2.1.2).
- The previous implementation did not take that into consideration.
- With this new implementation, v2.1.2 is returned even when v2 is the newer commit tag (which is usually the case).
- Also, when running this script from another branch (let's say 'releases/v1'), the previous implementation would return newer tags in other branches.
- NOTE: This new implementation only searches for annotated tags.
This commit is contained in:
Paul Ebose 2024-07-01 02:37:14 +01:00
parent 67934fecc6
commit be270a6def
No known key found for this signature in database
GPG Key ID: 2FF647AADFAC0FE8

View File

@ -20,6 +20,7 @@
# Variables
tag_regex='v[0-9]+\.[0-9]+\.[0-9]+$'
tag_glob='v[0-9].[0-9].[0-9]*'
# Terminal colors
OFF='\033[0m'
@ -28,7 +29,7 @@ GREEN='\033[0;32m'
BLUE='\033[0;34m'
# Get the latest release tag
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
latest_tag=$(git describe --abbrev=0 --match="$tag_glob")
if [[ -z "$latest_tag" ]]; then
# There are no existing release tags