Skip to content

Commit 97a8dba

Browse files
authored
Make git commit hash optional in landing page (payjoin#1408)
2 parents d9931d3 + 0a11989 commit 97a8dba

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

payjoin-mailroom/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::process::Command;
22

33
fn main() {
4-
// Emit the short git commit hash at build time.
5-
let commit = Command::new("git")
4+
// Emit the short git commit hash at build time when available.
5+
if let Some(commit) = Command::new("git")
66
.args(["rev-parse", "--short", "HEAD"])
77
.output()
88
.ok()
99
.filter(|o| o.status.success())
1010
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
11-
.unwrap_or_else(|| "unknown".into());
12-
13-
println!("cargo:rustc-env=GIT_COMMIT={commit}");
11+
{
12+
println!("cargo:rustc-env=GIT_COMMIT={commit}");
13+
}
1414

1515
// Re-run if HEAD changes (new commit).
1616
println!("cargo:rerun-if-changed=../.git/HEAD");

payjoin-mailroom/src/directory.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,11 @@ fn handle_peek<E: SendableError>(
436436
fn landing_page_html() -> String {
437437
const TEMPLATE: &str = include_str!("../static/index.html");
438438
const VERSION: &str = env!("CARGO_PKG_VERSION");
439-
const COMMIT: &str = env!("GIT_COMMIT");
440-
TEMPLATE.replace("{{VERSION}}", VERSION).replace("{{COMMIT}}", COMMIT)
439+
let version_string = match option_env!("GIT_COMMIT") {
440+
Some(commit) => format!("payjoin-mailroom-v{VERSION} @ {commit}"),
441+
None => format!("payjoin-mailroom-v{VERSION}"),
442+
};
443+
TEMPLATE.replace("{{VERSION_STRING}}", &version_string)
441444
}
442445

443446
async fn handle_directory_home_path() -> Result<Response<Body>, HandlerError> {
@@ -799,7 +802,6 @@ mod tests {
799802
#[test]
800803
fn landing_page_contains_version() {
801804
let html = landing_page_html();
802-
assert!(!html.contains("{{VERSION}}"));
803-
assert!(!html.contains("{{COMMIT}}"));
805+
assert!(!html.contains("{{VERSION_STRING}}"));
804806
}
805807
}

payjoin-mailroom/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ <h2>OHTTP Relay</h2>
242242
</main>
243243

244244
<footer>
245-
<span><code>payjoin-mailroom-v{{VERSION}} @ {{COMMIT}}</code></span>
245+
<span><code>{{VERSION_STRING}}</code></span>
246246
<span
247247
>Copyright &copy;
248248
<script>

0 commit comments

Comments
 (0)