From c51365c634c9687009778caf097ba059b88f8805 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 29 May 2018 08:39:46 +0200 Subject: [PATCH] script: Use source data from environment when generating assets --- script/genassets.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/script/genassets.go b/script/genassets.go index 63d04fa34..5d0dfbc14 100644 --- a/script/genassets.go +++ b/script/genassets.go @@ -17,6 +17,7 @@ import ( "io" "os" "path/filepath" + "strconv" "strings" "text/template" "time" @@ -87,9 +88,17 @@ func main() { filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0))) var buf bytes.Buffer + + // Generated time is now, except if the SOURCE_DATE_EPOCH environment + // variable is set (for reproducible builds). + generated := time.Now().Unix() + if s, _ := strconv.ParseInt(os.Getenv("SOURCE_DATE_EPOCH"), 10, 64); s > 0 { + generated = s + } + tpl.Execute(&buf, templateVars{ Assets: assets, - Generated: time.Now().Unix(), + Generated: generated, }) bs, err := format.Source(buf.Bytes()) if err != nil {