forked from pool/golang-github-prometheus-promu
- Set build date from last changelog modification (boo#1047218) OBS-URL: https://build.opensuse.org/request/show/973943 OBS-URL: https://build.opensuse.org/package/show/server:monitoring/golang-github-prometheus-promu?expand=0&rev=17
54 lines
1.5 KiB
Diff
54 lines
1.5 KiB
Diff
From 2098a5128565a72fc1886e996a444cc111e43c36 Mon Sep 17 00:00:00 2001
|
|
From: Witek Bedyk <witold.bedyk@suse.com>
|
|
Date: Tue, 26 Apr 2022 17:21:46 +0200
|
|
Subject: [PATCH] Set build date from SOURCE_DATE_EPOCH
|
|
|
|
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 PR was done while working on [reproducible builds for
|
|
openSUSE](https://en.opensuse.org/openSUSE:Reproducible_Builds).
|
|
|
|
Signed-off-by: Witek Bedyk <witold.bedyk@suse.com>
|
|
---
|
|
cmd/build.go | 10 +++++++++-
|
|
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/cmd/build.go b/cmd/build.go
|
|
index 18f1c5e..694b964 100644
|
|
--- a/cmd/build.go
|
|
+++ b/cmd/build.go
|
|
@@ -20,6 +20,7 @@ import (
|
|
"log"
|
|
"os"
|
|
"path"
|
|
+ "strconv"
|
|
"strings"
|
|
"text/template"
|
|
"time"
|
|
@@ -146,10 +147,17 @@ func getLdflags(info repository.Info) string {
|
|
var ldflags []string
|
|
|
|
if len(strings.TrimSpace(config.Build.LDFlags)) > 0 {
|
|
+ var buildDate time.Time
|
|
+ unixBuildDate, err := strconv.ParseInt(os.Getenv("SOURCE_DATE_EPOCH"), 10, 64)
|
|
+ if err == nil {
|
|
+ buildDate = time.Unix(unixBuildDate, 0)
|
|
+ } else {
|
|
+ buildDate = time.Now()
|
|
+ }
|
|
var (
|
|
tmplOutput = new(bytes.Buffer)
|
|
fnMap = template.FuncMap{
|
|
- "date": time.Now().UTC().Format,
|
|
+ "date": buildDate.UTC().Format,
|
|
"host": os.Hostname,
|
|
"repoPath": RepoPathFunc,
|
|
"user": UserFunc,
|
|
--
|
|
2.34.1
|
|
|