Skip to content

Commit 24d02ad

Browse files
committed
Allow to override build date with SOURCE_DATE_EPOCH
in order 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.
1 parent 9e91a03 commit 24d02ad

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

magefile.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"path/filepath"
1515
"regexp"
1616
"runtime"
17+
"strconv"
1718
"strings"
1819
"time"
1920

@@ -100,6 +101,14 @@ func Clean() error {
100101

101102
func flags() string {
102103
timestamp := time.Now().Format(time.RFC3339)
104+
source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH")
105+
if source_date_epoch != "" {
106+
sde, err := strconv.ParseInt(source_date_epoch, 10, 64)
107+
if err != nil {
108+
panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err))
109+
}
110+
timestamp = time.Unix(sde, 0).UTC().Format(time.RFC3339)
111+
}
103112
hash := hash()
104113
tag := tag()
105114
if tag == "" {

0 commit comments

Comments
 (0)