From 594b7a88eeb20f84574d5d3f6fe7492285346c28 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" <bwiedemann@suse.de> Date: Tue, 4 Mar 2025 11:45:48 +0100 Subject: [PATCH] Allow to override build date with SOURCE_DATE_EPOCH 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 patch was done while working on reproducible builds for openSUSE. --- doc/rest_docs.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/rest_docs.go b/doc/rest_docs.go index c33acc2b..7b9a2630 100644 --- a/doc/rest_docs.go +++ b/doc/rest_docs.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "sort" + "strconv" "strings" "time" @@ -123,7 +124,14 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str buf.WriteString("\n") } if !cmd.DisableAutoGenTag { - buf.WriteString("*Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "*\n") + now := time.Now() + if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" { + unixEpoch, err := strconv.ParseInt(epoch, 10, 64) + if err == nil { + now = time.Unix(unixEpoch, 0) + } + } + buf.WriteString("*Auto generated by spf13/cobra on " + now.Format("2-Jan-2006") + "*\n") } _, err := buf.WriteTo(w) return err