Skip to content

Commit 274493d

Browse files
replicate #502 on the android SDK build script (#503)
1 parent 45ef3a1 commit 274493d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

swift-ci/sdks/android/scripts/build.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,32 @@ function describe {
189189
if [[ "${SWIFT_BUILD_DOCKER}" == "1" ]]; then
190190
git config --global --add safe.directory $(pwd)
191191
fi
192-
git describe --tags
192+
193+
desc=$(git describe --tags)
194+
extra=
195+
196+
# Although git describe is documented as returning the newest tag,
197+
# if a given revision has multiple tags, it will actually return
198+
# the first one it finds, so we have some more work to do here.
199+
200+
# If we aren't pointing directly at a tag, git describe will append
201+
# -<number-of-commits>-g<truncated-hash> to the nearest tag. Strip
202+
# this, but keep a note of it for later.
203+
if [[ $desc =~ '-[0-9]+-g[0-9a-f]{11}$' ]]; then
204+
stripped=${desc%-*-g*}
205+
extra=${desc#$stripped}
206+
desc=$stripped
207+
fi
208+
209+
# Get the hash for the tag
210+
rev=$(git rev-list -n 1 tags/$desc)
211+
212+
# Now find the newest tag at that hash, using version number ordering
213+
latest_tag=$(git tag --points-at $rev | sort -V | tail -n 1)
214+
215+
# Stick it all back together
216+
echo $latest_tag$extra
217+
193218
popd >/dev/null 2>&1
194219
}
195220
function versionFromTag {

0 commit comments

Comments
 (0)