From b751d102f158968aab681cb663d27b4c32197f62 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Tue, 2 Jun 2026 21:48:02 +0300 Subject: feat: add preview update channel --- src/build_info.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/build_info.rs (limited to 'src/build_info.rs') diff --git a/src/build_info.rs b/src/build_info.rs new file mode 100644 index 00000000..1fdedfbb --- /dev/null +++ b/src/build_info.rs @@ -0,0 +1,44 @@ +//! Build identity helpers. + +pub const BASE_VERSION: &str = env!("CARGO_PKG_VERSION"); + +pub fn channel() -> &'static str { + non_empty(option_env!("HERDR_BUILD_CHANNEL")).unwrap_or("stable") +} + +pub fn build_id() -> Option<&'static str> { + non_empty(option_env!("HERDR_BUILD_ID")) +} + +pub fn version() -> String { + match channel() { + "stable" => BASE_VERSION.to_string(), + channel => match build_id() { + Some(build_id) => format!("{BASE_VERSION}-{channel}.{build_id}"), + None => format!("{BASE_VERSION}-{channel}"), + }, + } +} + +pub fn is_preview() -> bool { + channel() == "preview" +} + +fn non_empty(value: Option<&'static str>) -> Option<&'static str> { + value.and_then(|value| { + let trimmed = value.trim(); + if trimmed.is_empty() { + None + } else { + Some(trimmed) + } + }) +} + +#[cfg(test)] +mod tests { + #[test] + fn stable_version_defaults_to_cargo_version() { + assert!(!super::version().is_empty()); + } +} -- cgit v1.2.3