From b86b7695e138f4d2b908a16fe954c1744cafeddc Mon Sep 17 00:00:00 2001 From: justiceadams Date: Thu, 2 Oct 2025 11:53:00 -0700 Subject: [PATCH] replicate #502 on the android SDK build script --- swift-ci/sdks/android/scripts/build.sh | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index db95012f..75f6467d 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -189,7 +189,32 @@ function describe { if [[ "${SWIFT_BUILD_DOCKER}" == "1" ]]; then git config --global --add safe.directory $(pwd) fi - git describe --tags + + desc=$(git describe --tags) + extra= + + # Although git describe is documented as returning the newest tag, + # if a given revision has multiple tags, it will actually return + # the first one it finds, so we have some more work to do here. + + # If we aren't pointing directly at a tag, git describe will append + # --g to the nearest tag. Strip + # this, but keep a note of it for later. + if [[ $desc =~ '-[0-9]+-g[0-9a-f]{11}$' ]]; then + stripped=${desc%-*-g*} + extra=${desc#$stripped} + desc=$stripped + fi + + # Get the hash for the tag + rev=$(git rev-list -n 1 tags/$desc) + + # Now find the newest tag at that hash, using version number ordering + latest_tag=$(git tag --points-at $rev | sort -V | tail -n 1) + + # Stick it all back together + echo $latest_tag$extra + popd >/dev/null 2>&1 } function versionFromTag {