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
This commit is contained in:
Witek Bedyk 2022-05-06 08:16:39 +00:00 committed by Git OBS Bridge
parent 59cfd435c1
commit 5b9d34c838
3 changed files with 61 additions and 2 deletions

View File

@ -0,0 +1,53 @@
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

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Apr 26 17:13:58 UTC 2022 - Witek Bedyk <witold.bedyk@suse.com>
- Set build date from last changelog modification (boo#1047218)
-------------------------------------------------------------------
Fri Apr 1 13:56:36 UTC 2022 - Stefan Bluhm <stefan.bluhm@clacee.eu>

View File

@ -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