scripts/build: Handle VERSION containing git ref

Transform `VERSION` variable if it contains a git ref.
This is the same as moby does (with "<<<" bashism removed).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-01-04 13:55:28 +01:00
parent 6ad07f2a4b
commit ecf338f43b
No known key found for this signature in database
GPG Key ID: B85EFCFE26DEF92A
1 changed files with 7 additions and 0 deletions

View File

@ -22,6 +22,13 @@ else
BUILDTIME=${BUILDTIME:-$(TZ=UTC date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")} BUILDTIME=${BUILDTIME:-$(TZ=UTC date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
fi fi
case "$VERSION" in
refs/tags/v*) VERSION=${VERSION#refs/tags/v} ;;
refs/tags/*) VERSION=${VERSION#refs/tags/} ;;
refs/heads/*) VERSION=$(echo "${VERSION#refs/heads/}" | sed -r 's#/+#-#g') ;;
refs/pull/*) VERSION=pr-$(echo "$VERSION" | grep -o '[0-9]\+') ;;
esac
GOOS="$(go env GOOS)" GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)" GOARCH="$(go env GOARCH)"
if [ "${GOARCH}" = "arm" ]; then if [ "${GOARCH}" = "arm" ]; then