diff --git a/crates/taurus-core/src/lib.rs b/crates/taurus-core/src/lib.rs index 96efe78..e487ab7 100644 --- a/crates/taurus-core/src/lib.rs +++ b/crates/taurus-core/src/lib.rs @@ -20,3 +20,4 @@ pub mod runtime; pub mod time; pub mod types; pub mod value; +pub mod version; diff --git a/crates/taurus-core/src/types/errors/runtime_error.rs b/crates/taurus-core/src/types/errors/runtime_error.rs index bfe6503..5bc8cb9 100644 --- a/crates/taurus-core/src/types/errors/runtime_error.rs +++ b/crates/taurus-core/src/types/errors/runtime_error.rs @@ -16,6 +16,7 @@ use tucana::shared::{ }; use crate::time::now_unix_micros; +use crate::version::runtime_version; /// Runtime execution failure representation. #[derive(Debug, Clone, PartialEq)] @@ -48,7 +49,7 @@ impl RuntimeError { category: category.into(), message: message.into(), timestamp_unix_micros: now_unix_micros() as u64, - version: env!("CARGO_PKG_VERSION").to_string(), + version: runtime_version().to_string(), dependencies: HashMap::new(), details: HashMap::new(), } diff --git a/crates/taurus-core/src/version.rs b/crates/taurus-core/src/version.rs new file mode 100644 index 0000000..785bfeb --- /dev/null +++ b/crates/taurus-core/src/version.rs @@ -0,0 +1,19 @@ +//! Runtime version resolution. +//! +//! `env!("CARGO_PKG_VERSION")` is a compile-time constant, so stamping a +//! per-pipeline release version into `Cargo.toml` before `cargo build` (as +//! CI used to) invalidates the build cache for every crate that reads it on +//! every single build. Reading `TAURUS_VERSION` at runtime instead lets the +//! image's final Docker layer stamp the release version without touching +//! anything upstream of it. Falls back to the compiled-in crate version when +//! the env var isn't set (local dev, tests). + +use std::sync::OnceLock; + +static VERSION: OnceLock = OnceLock::new(); + +pub fn runtime_version() -> &'static str { + VERSION.get_or_init(|| { + std::env::var("TAURUS_VERSION").unwrap_or_else(|_| env!("CARGO_PKG_VERSION").to_string()) + }) +} diff --git a/crates/taurus/src/app/mod.rs b/crates/taurus/src/app/mod.rs index 4e81e18..4164fd4 100644 --- a/crates/taurus/src/app/mod.rs +++ b/crates/taurus/src/app/mod.rs @@ -87,7 +87,7 @@ fn init_telemetry(config: &Config) -> telemetry::Telemetry { TelemetrySettings { environment: environment_label(&config.environment), default_log_level: "debug", - service_version: env!("CARGO_PKG_VERSION"), + service_version: taurus_core::version::runtime_version(), instrumentation_name: env!("CARGO_PKG_NAME"), initialize_metrics: Some(telemetry::metrics::initialize), },