Skip to content
Myr

doc: obey SOURCE_DATE_EPOCH with manpage generation (#735)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Previously if a cobra user didn't specify an explicit .Date header, the current time would be included in all of the generated man pages each time they were built. This causes an issue for reproducible builds, since each re-build of a package that includes the man pages will have different times listed in the man pages. To fix this, add support for SOURCE_DATE_EPOCH (which is a standardised packaging environment variable, designed to be used specifically for this purpose[1]). [1]: https://reproducible-builds.org/specs/source-date-epoch/

authored by Aleksa Sarai · committed by Eric Paris · parent f619abc · Browse files · 1 file+13 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Aleksa Sarai <asarai@suse.de>

Diff stats

1 file+13 added−2 removed

  • other:+13 added−2 removed

1 file+13 added−2 removed

modified:doc/man_docs.go+13 added-2 removed
18 unmodified lines
19 "io"20 "os"21 "path/filepath"22 "sort"23 "strconv"24 "strings"25 "time"2627 "github.com/cpuguy83/go-md2man/md2man"
76 unmodified lines
104func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {105 if header == nil {106 header = &GenManHeader{}107 }107 fillHeader(header, cmd.CommandPath())108 if err := fillHeader(header, cmd.CommandPath()); err != nil {109 return err110 }111112 b := genMan(cmd, header)113 _, err := w.Write(md2man.Render(b))114 return err115}116114func fillHeader(header *GenManHeader, name string) {117func fillHeader(header *GenManHeader, name string) error {118 if header.Title == "" {119 header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))120 }121 if header.Section == "" {122 header.Section = "1"123 }124 if header.Date == nil {125 now := time.Now()126 if epoch := os.Getenv("SOURCE_DATE_EPOCH"); epoch != "" {127 unixEpoch, err := strconv.ParseInt(epoch, 10, 64)128 if err != nil {129 return fmt.Errorf("invalid SOURCE_DATE_EPOCH: %v", err)130 }131 now = time.Unix(unixEpoch, 0)132 }133 header.Date = &now134 }135 header.date = (*header.Date).Format("Jan 2006")136 if header.Source == "" {137 header.Source = "Auto generated by spf13/cobra"138 }139 return nil140}141142func manPreamble(buf *bytes.Buffer, header *GenManHeader, cmd *cobra.Command, dashedName string) {143 description := cmd.Long
104 unmodified lines