Allow to override build date with SOURCE_DATE_EPOCH (#2202)

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 patch was done while working on reproducible builds for openSUSE.

---------

Co-authored-by: extrawurst <mail@rusticorn.com>
This commit is contained in:
Bernhard M. Wiedemann 2024-05-16 17:17:58 +02:00 committed by GitHub
parent 3dca5feeec
commit f56844501e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* respect configuration for remote when fetching (also applies to pulling) [[@cruessler](https://github.com/cruessler)] ([#1093](https://github.com/extrawurst/gitui/issues/1093))
* add `:` character to sign-off trailer to comply with Conventinoal Commits standard [@semioticrobotic](https://github.com/semioticrobotic) ([#2196](https://github.com/extrawurst/gitui/issues/2196))
### Added
* support overriding `build_date` for [reproducible builds](https://reproducible-builds.org/) [[@bmwiedemann](https://github.com/bmwiedemann)] ([#2202](https://github.com/extrawurst/gitui/pull/2202))
## [0.26.0+1] - 2024-04-14
**0.26.1**

View file

@ -1,3 +1,5 @@
use chrono::TimeZone;
fn get_git_hash() -> String {
use std::process::Command;
@ -18,7 +20,13 @@ fn get_git_hash() -> String {
}
fn main() {
let build_date = chrono::Local::now().date_naive();
let now = match std::env::var("SOURCE_DATE_EPOCH") {
Ok(val) => chrono::Local
.timestamp_opt(val.parse::<i64>().unwrap(), 0)
.unwrap(),
Err(_) => chrono::Local::now(),
};
let build_date = now.date_naive();
let build_name = if std::env::var("GITUI_RELEASE").is_ok() {
format!(