1
0
Fork 0
mirror of https://github.com/spf13/cobra synced 2025-04-07 15:29:16 +00:00

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.
This commit is contained in:
Bernhard M. Wiedemann 2025-03-04 11:45:48 +01:00
parent 1995054b00
commit 594b7a88ee
No known key found for this signature in database
GPG key ID: 8D6B1CBF0689344C

View file

@ -21,6 +21,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv"
"strings" "strings"
"time" "time"
@ -123,7 +124,14 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
buf.WriteString("\n") buf.WriteString("\n")
} }
if !cmd.DisableAutoGenTag { 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) _, err := buf.WriteTo(w)
return err return err