Skip to content

Commit 17a21b8

Browse files
committed
static: make gen-static-ver work natively on macOS
macOS uses the BSD flavor of `date`, which does not support the `--date` option to set a custom time. Previously, we were using an alpine container to provide a GNU flavor of date, which was a bit of a hack. This patch rewrites the script to work on macOS directly, without the need of a container: ./static/gen-static-ver . v1.2.3-dev 0.0.0-20220404154104-b815498 docker run --rm -v $(pwd):/src -w /src golang bash -c './static/gen-static-ver . v1.2.3-dev' 0.0.0-20220404154104-b815498 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b815498 commit 17a21b8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

static/gen-static-ver

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ staticVersion="$VERSION"
1515
if [[ "$VERSION" == *-dev ]]; then
1616
export TZ=UTC
1717

18-
DATE_COMMAND="date"
19-
if [[ $(uname) == "Darwin" ]]; then
20-
DATE_COMMAND="docker run --rm alpine date"
21-
fi
22-
2318
# based on golang's pseudo-version: https://groups.google.com/forum/#!topic/golang-dev/a5PqQuBljF4
2419
#
2520
# using a "pseudo-version" of the form v0.0.0-yyyymmddhhmmss-abcdefabcdef,
@@ -30,7 +25,16 @@ if [[ "$VERSION" == *-dev ]]; then
3025
# as a pre-release before version v0.0.0, so that the go command prefers any
3126
# tagged release over any pseudo-version.
3227
gitUnix="$($GIT_COMMAND log -1 --pretty='%ct')"
33-
gitDate="$($DATE_COMMAND --utc --date "@$gitUnix" +'%Y%m%d%H%M%S')"
28+
29+
if [ "$(uname)" = "Darwin" ]; then
30+
# Using BSD date (macOS), which doesn't suppoort the --date option
31+
# date -jf "<input format>" "<input value>" +"<output format>" (https://unix.stackexchange.com/a/86510)
32+
gitDate="$(TZ=UTC date -jf "%s" "$gitUnix" +'%Y%m%d%H%M%S')"
33+
else
34+
# Using GNU date (Linux)
35+
gitDate="$(TZ=UTC date --utc --date "@$gitUnix" +'%Y%m%d%H%M%S')"
36+
fi
37+
3438
gitCommit="$($GIT_COMMAND log -1 --pretty='%h')"
3539
# generated version is now something like '0.0.0-20180719213702-cd5e2db'
3640
staticVersion="0.0.0-${gitDate}-${gitCommit}"

0 commit comments

Comments
 (0)