@@ -536,17 +536,37 @@ set_info_git() {
536
536
# Get the tag for the HEAD.
537
537
si_previous_tag=
538
538
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.
542
562
si_project_version=" $si_tag "
543
563
# 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
545
565
# --abbrev=0 expands out the full sha if there was no previous tag
546
566
si_project_version=" $_si_tag "
547
567
si_previous_tag=
548
568
si_tag=
549
- elif [ " $_si_tag " != " $si_tag " ]; then
569
+ elif [[ $_si_tag != " $si_tag " ] ]; then
550
570
# not on a tag
551
571
si_project_version=$( git -C " $si_repo_dir " describe --tags --abbrev=7 --exclude=" *[Aa][Ll][Pp][Hh][Aa]*" 2> /dev/null )
552
572
if [[ -n $si_project_version ]]; then
0 commit comments