From 5b9d34c83870aeca8556e32e4605666f837ddaf28d5d735cde684e6b93e9a1c3 Mon Sep 17 00:00:00 2001 From: Witek Bedyk Date: Fri, 6 May 2022 08:16:39 +0000 Subject: [PATCH 1/2] Accepting request 973943 from home:witekbedyk:branches:server:monitoring - 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 --- ...et-build-date-from-SOURCE_DATE_EPOCH.patch | 53 +++++++++++++++++++ golang-github-prometheus-promu.changes | 5 ++ golang-github-prometheus-promu.spec | 5 +- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch 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 From 28750ae182e65ba5a8957b982ba807a10644d2a224f08bbd61648d280c196930 Mon Sep 17 00:00:00 2001 From: Dirk Stoecker Date: Wed, 11 May 2022 16:45:14 +0000 Subject: [PATCH 2/2] Accepting request 975358 from home:witekbedyk:branches:server:monitoring Update changelog OBS-URL: https://build.opensuse.org/request/show/975358 OBS-URL: https://build.opensuse.org/package/show/server:monitoring/golang-github-prometheus-promu?expand=0&rev=18 --- golang-github-prometheus-promu.changes | 1 + 1 file changed, 1 insertion(+) diff --git a/golang-github-prometheus-promu.changes b/golang-github-prometheus-promu.changes index b7f65b6..e1f8b8f 100644 --- a/golang-github-prometheus-promu.changes +++ b/golang-github-prometheus-promu.changes @@ -2,6 +2,7 @@ Tue Apr 26 17:13:58 UTC 2022 - Witek Bedyk - Set build date from last changelog modification (boo#1047218) +- Add 0001-Set-build-date-from-SOURCE_DATE_EPOCH.patch ------------------------------------------------------------------- Fri Apr 1 13:56:36 UTC 2022 - Stefan Bluhm