Skip to content

Commit a8acbfa

Browse files
committed
Improve current tag selection
1 parent 53d8a49 commit a8acbfa

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

release.sh

+25-5
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,37 @@ set_info_git() {
536536
# Get the tag for the HEAD.
537537
si_previous_tag=
538538
si_previous_revision=
539-
_si_tag=$( git -C "$si_repo_dir" describe --tags --always --abbrev=7 2>/dev/null )
540-
si_tag=$( git -C "$si_repo_dir" describe --tags --always --abbrev=0 2>/dev/null )
541-
# Set $si_project_version to the version number of HEAD. May be empty if there are no commits.
539+
# git describe should use the latest tag if there are multiple, but it doesn't always work that way.
540+
check_tag=()
541+
while IFS='' read -r tag; do check_tag+=( "$tag" ); done < <( git -C "$si_repo_dir" tag --points-at HEAD --sort=-committerdate --sort=-v:refname --sort=-taggerdate )
542+
if [[ ${#check_tag[@]} -gt 0 ]]; then
543+
# Use the most recent tag
544+
si_tag="${check_tag[0]}"
545+
_si_tag="$si_tag"
546+
547+
if [[ $GITHUB_REF == "refs/tags/"* && $si_tag != "$GITHUB_REF_NAME" ]]; then
548+
# Git doesn't agree with GitHub Actions, check if there is another local tag that matches
549+
for tag in "${check_tag[@]}"; do
550+
if [[ $tag == "$GITHUB_REF_NAME" ]]; then
551+
si_tag="$GITHUB_REF_NAME"
552+
_si_tag="$si_tag"
553+
break
554+
fi
555+
done
556+
fi
557+
else
558+
_si_tag=$( git -C "$si_repo_dir" describe --tags --always --abbrev=7 2>/dev/null )
559+
si_tag=$( git -C "$si_repo_dir" describe --tags --always --abbrev=0 2>/dev/null )
560+
fi
561+
# Set $si_project_version to the version number of HEAD.
542562
si_project_version="$si_tag"
543563
# The HEAD is not tagged if the HEAD is several commits past the most recent tag.
544-
if [ "$si_tag" = "$si_project_hash" ]; then
564+
if [[ $si_tag == "$si_project_hash" ]]; then
545565
# --abbrev=0 expands out the full sha if there was no previous tag
546566
si_project_version="$_si_tag"
547567
si_previous_tag=
548568
si_tag=
549-
elif [ "$_si_tag" != "$si_tag" ]; then
569+
elif [[ $_si_tag != "$si_tag" ]]; then
550570
# not on a tag
551571
si_project_version=$( git -C "$si_repo_dir" describe --tags --abbrev=7 --exclude="*[Aa][Ll][Pp][Hh][Aa]*" 2>/dev/null )
552572
if [[ -n $si_project_version ]]; then

0 commit comments

Comments
 (0)