diff --git a/0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch b/0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch new file mode 100644 index 0000000..a4be429 --- /dev/null +++ b/0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch @@ -0,0 +1,53 @@ +From 2098a5128565a72fc1886e996a444cc111e43c36 Mon Sep 17 00:00:00 2001 +From: Witek Bedyk +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 +--- + 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 + diff --git a/golang-github-prometheus-promu.changes b/golang-github-prometheus-promu.changes index 80f26f3..b7f65b6 100644 --- a/golang-github-prometheus-promu.changes +++ b/golang-github-prometheus-promu.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Apr 26 17:13:58 UTC 2022 - Witek Bedyk + +- Set build date from last changelog modification (boo#1047218) + ------------------------------------------------------------------- Fri Apr 1 13:56:36 UTC 2022 - Stefan Bluhm diff --git a/golang-github-prometheus-promu.spec b/golang-github-prometheus-promu.spec index bf0a472..71154ea 100644 --- a/golang-github-prometheus-promu.spec +++ b/golang-github-prometheus-promu.spec @@ -15,6 +15,7 @@ # Please submit bugfixes or comments via https://bugs.opensuse.org/ # + %if 0%{?rhel} # Fix ERROR: No build ID note found in %undefine _missing_build_ids_terminate_build @@ -31,6 +32,7 @@ Group: System/Management URL: https://github.com/prometheus/promu Source: promu-%{version}.tar.gz Source1: vendor.tar.gz +Patch1: 0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch BuildRequires: golang-packaging %if 0%{?rhel} BuildRequires: golang >= 1.15 @@ -44,8 +46,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build The Prometheus Utility Tool is used by the Prometheus project to build other components. %prep -%setup -q -n promu-%{version} -%setup -q -T -D -a 1 -n promu-%{version} +%autosetup -a1 -p1 -n promu-%{version} %build %goprep github.com/prometheus/promu