Skip to content

Commit a7ad827

Browse files
author
Bernhard M. Wiedemann
authored
Allow to override build date with SOURCE_DATE_EPOCH (#887)
in order to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. This date call works with different variants of date. Also use UTC to be independent of timezone.
1 parent 26f0389 commit a7ad827

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ GIT_TAG?= $(shell git describe --always --tags)
22
BIN = gosec
33
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
44
IMAGE_REPO = securego
5-
BUILD_DATE ?= $(shell date +%Y-%m-%d)
5+
DATE_FMT=+%Y-%m-%d
6+
ifdef SOURCE_DATE_EPOCH
7+
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
8+
else
9+
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
10+
endif
611
BUILDFLAGS := "-w -s -X 'main.Version=$(GIT_TAG)' -X 'main.GitTag=$(GIT_TAG)' -X 'main.BuildDate=$(BUILD_DATE)'"
712
CGO_ENABLED = 0
813
GO := GO111MODULE=on go

0 commit comments

Comments
 (0)