Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/bin/uudoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use fluent_syntax::{
},
parser,
};
use jiff::Zoned;
use jiff::{Timestamp, Zoned, tz::TimeZone};
use regex::Regex;
use textwrap::{fill, indent, termwidth};
use zip::ZipArchive;
Expand Down Expand Up @@ -167,8 +167,15 @@ fn gen_manpage<T: Args>(
// Convert to string for processing
let manpage = String::from_utf8(buffer).expect("Invalid UTF-8 in manpage");

// Use `SOURCE_DATE_EPOCH` for reproducible builds if set and valid; otherwise use the current time.
let now = std::env::var("SOURCE_DATE_EPOCH")
.ok()
.and_then(|s| s.parse().ok())
.and_then(|s| Timestamp::new(s, 0).ok())
.map_or_else(Zoned::now, |t| t.to_zoned(TimeZone::UTC));

// Post-process the manpage to fix mandoc lint issues
let date = Zoned::now().strftime("%Y-%m-%d").to_string();
let date = now.strftime("%Y-%m-%d").to_string();
let processed_manpage = post_process_manpage(manpage, &date);

// Write the processed manpage to stdout
Expand Down
28 changes: 28 additions & 0 deletions tests/uudoc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,31 @@ fn test_markdown_header_format() {
}
}
}

#[test]
fn test_source_date_epoch() {
let output = get_uudoc_command()
.arg("manpage")
.arg("ls")
.env("SOURCE_DATE_EPOCH", "123456")
.output()
.expect("Failed to execute command");

assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
assert!(
output.stderr.is_empty(),
"stderr should be empty but got: {}",
String::from_utf8_lossy(&output.stderr)
);

let output_str = String::from_utf8_lossy(&output.stdout);
let first_line = output_str
.lines()
.find(|line| line.starts_with(".TH"))
.unwrap();
assert_eq!(first_line, ".TH LS 1 \"1970-01-02\"");
}
Loading