@@ -887,52 +887,48 @@ gomod-pseudo-version() {
887887 local commit_ts
888888 commit_ts=" $( TZ=UTC git show -s --date=' format-local:%Y%m%d%H%M%S' --format=%cd HEAD) "
889889
890- local tag
891- tag =" $( git describe --tags --abbrev=0 -- match ' v[0-9]* ' 2> /dev/null || true) "
890+ local commit_tag
891+ commit_tag =" $( git describe --tags --exact- match --abbrev=0 2> /dev/null || true) "
892892
893- # tag does not exist at all -> v0.0.0-<timestamp>-<hash>
894- if [[ -z " ${tag :- } " ]]; then
895- echo " v0.0.0- ${commit_ts} - ${commit_sha }"
893+ # latest commit has a tag -> tag
894+ if [[ -n " ${commit_tag } " ]]; then
895+ echo " ${commit_tag }"
896896 return
897897 fi
898898
899- local head_rev
900- head_rev=" $( git rev-parse HEAD) "
901- local tag_rev
902- tag_rev=" $( git rev-list -n1 " $tag " ) "
903-
904- # tag on head -> tag
905- if [[ " $head_rev " == " $tag_rev " ]]; then
906- echo " $tag "
899+ local latest_tag
900+ latest_tag=" $( git ls-remote --tags origin 2> /dev/null | awk -F/ ' {print $3}' | grep -E ' ^v[0-9]+(\.[0-9]+)*$' | sort -V | tail -n1) "
901+
902+ # tag does not exist at all -> v0.0.0-<timestamp>-<hash>
903+ if [[ -z " ${latest_tag:- } " ]]; then
904+ echo " v0.0.0-${commit_ts} -${commit_sha} "
907905 return
908906 fi
909907
910- local current_major
911- current_major =" $( grep ' ^module ' go.mod | sed -E ' s|^module .*/(v[0-9]+)$|\1|; t; s|.*|v0|' ) "
908+ local module_major
909+ module_major =" $( grep ' ^module ' go.mod | sed -E ' s|^module .*/(v[0-9]+)$|\1|; t; s|.*|v0|' ) "
912910
913911 # head is not a tag ->
914912 # - the latest available tag is vX.Y.Z -> vX.Y.(Z+1)-0.<timestamp>-<hash>
915913 # - the latest available tag is vX.Y.Z-PR -> vX.Y.Z-PR.0.<timestamp>-<hash>
916- if [[ " $tag " =~ ^v([0-9]+)\. ([0-9]+)\. ([0-9]+)(-.+)? $ ]]; then
914+ if [[ " $latest_tag " =~ ^v([0-9]+)\. ([0-9]+)\. ([0-9]+)(-.+)? $ ]]; then
917915 local major=" ${BASH_REMATCH[1]} "
918916 local minor=" ${BASH_REMATCH[2]} "
919917 local patch=" ${BASH_REMATCH[3]} "
920918 local pre=" ${BASH_REMATCH[4]} "
921919
922- # if go.mod major matches the latest tag major
923- if [[ " $current_major " == " v$major " ]]; then
920+ if [[ " $module_major " == " v$major " ]]; then
924921 if [[ -z " ${pre} " ]]; then
925922 echo " v${major} .${minor} .$(( patch+ 1 )) -0.${commit_ts} -${commit_sha} "
926923 else
927- echo " ${tag } .0.${commit_ts} -${commit_sha} "
924+ echo " ${latest_tag } .0.${commit_ts} -${commit_sha} "
928925 fi
929- # if go.mod major does not match the latest tag major, then logic similar to v0.0.0 is used
930926 else
931- echo " ${current_major} .0.0- ${commit_ts} - ${commit_sha} "
927+ echo " ${latest_tag} +incompatible "
932928 fi
933929 else
934930 # the latest tag is not semver -> ignore it
935- echo " ${current_major} .0.0-${commit_ts} -${commit_sha} "
931+ echo " v0 .0.0-${commit_ts} -${commit_sha} "
936932 fi
937933}
938934
0 commit comments