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:
parent
1995054b00
commit
594b7a88ee
1 changed files with 9 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue