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.
This commit is contained in:
Bernhard M. Wiedemann 2018-04-07 20:49:55 +02:00
parent 4dab30cb33
commit fb660d6634

View file

@ -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"
}