Merge pull request #3535 from thaJeztah/fix_date_on_macos

scripts/build: fix build-date generation on macOS, and make sure it's in UTC
This commit is contained in:
Sebastiaan van Stijn 2022-04-06 12:53:31 +02:00 committed by GitHub
commit 73b05aaa82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -12,7 +12,15 @@ TARGET=${TARGET:-"build"}
PLATFORM=${PLATFORM:-}
VERSION=${VERSION:-$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags | sed 's/^v//' 2>/dev/null || echo "unknown-version" )}
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
BUILDTIME=${BUILDTIME:-$(date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
if [ "$(uname)" = "Darwin" ]; then
# Using BSD date (macOS), which doesn't suppoort the --date option
# date -jf "<input format>" "<input value>" +"<output format>" (https://unix.stackexchange.com/a/86510)
BUILDTIME=${BUILDTIME:-$(TZ=UTC date -jf "%s" "${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
else
# Using GNU date (Linux)
BUILDTIME=${BUILDTIME:-$(TZ=UTC date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
fi
GOOS="$(go env GOOS)"
GOARCH="$(go env GOARCH)"