From fb660d6634c6cf87be629d7dd4a67166607f86bf Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Sat, 7 Apr 2018 20:49:55 +0200 Subject: [PATCH] Allow to override build date via environment variable in order to make builds easily 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. Also use UTC to be independent of timezones. Without this change, docker-17.09.1 package man pages varied over time. --- doc/man_docs.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/man_docs.go b/doc/man_docs.go index ce92332d..4a7b6ee6 100644 --- a/doc/man_docs.go +++ b/doc/man_docs.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "sort" + "strconv" "strings" "time" @@ -87,6 +88,7 @@ type GenManTreeOptions struct { // GenManHeader is a lot like the .TH header at the start of man pages. These // include the title, section, date, source, and manual. We will use the +// SOURCE_DATE_EPOCH environment variable (if set) or the // current time if Date if unset and will use "Auto generated by spf13/cobra" // if the Source is unset. type GenManHeader struct { @@ -120,9 +122,17 @@ func fillHeader(header *GenManHeader, name string) { } if header.Date == nil { now := time.Now() + source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH") + if source_date_epoch != "" { + sde, err := strconv.ParseInt(source_date_epoch, 10, 64) + if err != nil { + panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err)) + } + now = time.Unix(sde, 0) + } header.Date = &now } - header.date = (*header.Date).Format("Jan 2006") + header.date = (*header.Date).UTC().Format("Jan 2006") if header.Source == "" { header.Source = "Auto generated by spf13/cobra" }