diff --git a/Cargo.lock b/Cargo.lock index f663c72543..aa0a1ac3af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5221,6 +5221,7 @@ dependencies = [ "tailcall-macros", "tailcall-prettier", "tailcall-tracker", + "tailcall-version", "temp-env", "tempfile", "thiserror", @@ -5338,6 +5339,7 @@ dependencies = [ "serde", "serde_json", "sysinfo 0.30.12", + "tailcall-version", "tokio", "tracing", ] @@ -5385,6 +5387,10 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tailcall-version" +version = "0.1.0" + [[package]] name = "tailcall_query_plan" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e217d46cd9..f0c992bce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ opentelemetry-otlp = { version = "0.15.0", features = [ ], optional = true } opentelemetry-system-metrics = { version = "0.1.8", optional = true } tailcall-http-cache = {path = "tailcall-http-cache", optional = true } +tailcall-version = { path = "./tailcall-version", optional = true } # dependencies safe for wasm: @@ -197,6 +198,7 @@ cli = [ "dep:opentelemetry-system-metrics", "dep:tailcall-tracker", "dep:tailcall-http-cache", + "dep:tailcall-version" ] # Feature flag to enable all default features. @@ -219,6 +221,7 @@ members = [ "tailcall-tracker", "tailcall-hasher", "tailcall-http-cache", + "tailcall-version", ] # Boost execution_spec snapshot diffing performance diff --git a/src/cli/command.rs b/src/cli/command.rs index 616371706d..8326f33ad9 100644 --- a/src/cli/command.rs +++ b/src/cli/command.rs @@ -1,12 +1,9 @@ use clap::{Parser, Subcommand}; use strum_macros::Display; +use tailcall_version::VERSION; use crate::core::{config, generator}; -pub const VERSION: &str = match option_env!("APP_VERSION") { - Some(version) => version, - _ => "0.1.0-dev", -}; const ABOUT: &str = r" __ _ __ ____ / /_____ _(_) /________ _/ / / @@ -15,7 +12,7 @@ const ABOUT: &str = r" \__/\__,_/_/_/\___/\__,_/_/_/"; #[derive(Parser)] -#[command(name = "tailcall", author, version = VERSION, about, long_about = Some(ABOUT))] +#[command(name = "tailcall", author, version = VERSION.as_str(), about, long_about = Some(ABOUT))] pub struct Cli { #[command(subcommand)] pub command: Command, diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 834b70d7fa..497016fab9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -7,7 +7,6 @@ pub mod metrics; pub mod server; mod tc; pub mod telemetry; -mod version; pub mod runtime; pub(crate) mod update_checker; diff --git a/src/cli/server/playground.rs b/src/cli/server/playground.rs index 8bb982a1e1..1c80f94479 100644 --- a/src/cli/server/playground.rs +++ b/src/cli/server/playground.rs @@ -1,4 +1,4 @@ -use crate::cli::version::VERSION; +use tailcall_version::VERSION; const UTM_MEDIUM: &str = "server"; const DEBUG_UTM_SOURCE: &str = "tailcall-debug"; diff --git a/src/cli/update_checker.rs b/src/cli/update_checker.rs index 714bfef53a..49aa5c1a03 100644 --- a/src/cli/update_checker.rs +++ b/src/cli/update_checker.rs @@ -1,9 +1,8 @@ use colored::Colorize; +use tailcall_version::VERSION; use update_informer::{registry, Check}; use which::which; -use crate::cli::command::VERSION; - enum InstallationMethod { Npm, Npx, @@ -37,14 +36,14 @@ fn get_installation_method() -> InstallationMethod { pub async fn check_for_update() { tokio::task::spawn_blocking(|| { - if VERSION.eq("0.1.0-dev") { + if VERSION.is_dev() { // skip validation if it's not a release return; } let name: &str = "tailcallhq/tailcall"; - let informer = update_informer::new(registry::GitHub, name, VERSION); + let informer = update_informer::new(registry::GitHub, name, VERSION.as_str()); if let Some(latest_version) = informer.check_version().ok().flatten() { let github_release_url = @@ -54,7 +53,7 @@ pub async fn check_for_update() { "{}", format!( "A new release of tailcall is available: {} {} {}", - VERSION.cyan(), + VERSION.as_str().cyan(), "➜".white(), latest_version.to_string().cyan() ) diff --git a/src/cli/version.rs b/src/cli/version.rs deleted file mode 100644 index b6d70c21a3..0000000000 --- a/src/cli/version.rs +++ /dev/null @@ -1,42 +0,0 @@ -const DEFAULT_VERSION: &str = "0.1.0-dev"; - -pub struct Version { - version: &'static str, -} - -impl Version { - pub const fn new(version: &'static str) -> Self { - Version { version } - } - - // pub const fn as_str(&self) -> &'static str { - // self.version - // } - - pub fn is_dev(&self) -> bool { - self.version == DEFAULT_VERSION - } -} - -pub const VERSION: Version = match option_env!("APP_VERSION") { - Some(version) => Version::new(version), - None => Version::new(DEFAULT_VERSION), -}; - -// #[cfg(test)] -// mod tests { -// use super::*; - -// #[test] -// fn test_default_version() { -// assert_eq!(VERSION.as_str(), DEFAULT_VERSION); -// assert!(VERSION.is_dev()); -// } - -// #[test] -// fn test_custom_version() { -// const CUSTOM_VERSION: Version = Version::new("1.0.0-release"); -// assert_eq!(CUSTOM_VERSION.as_str(), "1.0.0-release"); -// assert!(!CUSTOM_VERSION.is_dev()); -// } -// } diff --git a/tailcall-tracker/Cargo.toml b/tailcall-tracker/Cargo.toml index 9261ff8a7f..e2dfd914a0 100644 --- a/tailcall-tracker/Cargo.toml +++ b/tailcall-tracker/Cargo.toml @@ -15,3 +15,4 @@ machineid-rs = "1.2.4" tokio = { workspace = true } tracing = { workspace = true } sysinfo = "0.30.12" +tailcall-version = { path = "../tailcall-version" } diff --git a/tailcall-tracker/src/check_tracking.rs b/tailcall-tracker/src/check_tracking.rs index 0da3349945..0698ae4b38 100644 --- a/tailcall-tracker/src/check_tracking.rs +++ b/tailcall-tracker/src/check_tracking.rs @@ -1,15 +1,13 @@ use std::env; +use tailcall_version::VERSION; + const LONG_ENV_FILTER_VAR_NAME: &str = "TAILCALL_TRACKER"; const SHORT_ENV_FILTER_VAR_NAME: &str = "TC_TRACKER"; -const VERSION: &str = match option_env!("APP_VERSION") { - Some(version) => version, - _ => "0.1.0-dev", -}; /// Checks if tracking is enabled pub fn check_tracking() -> bool { - let is_prod = !VERSION.contains("dev"); + let is_prod = !VERSION.is_dev(); let usage_enabled = env::var(LONG_ENV_FILTER_VAR_NAME) .or(env::var(SHORT_ENV_FILTER_VAR_NAME)) .map(|v| !v.eq_ignore_ascii_case("false")) diff --git a/tailcall-version/Cargo.toml b/tailcall-version/Cargo.toml new file mode 100644 index 0000000000..7f799f6bbd --- /dev/null +++ b/tailcall-version/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "tailcall-version" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/tailcall-version/src/lib.rs b/tailcall-version/src/lib.rs new file mode 100644 index 0000000000..6c73448d31 --- /dev/null +++ b/tailcall-version/src/lib.rs @@ -0,0 +1,42 @@ +const DEFAULT_VERSION: &str = "0.1.0-dev"; + +pub struct Version { + version: &'static str, +} + +impl Version { + pub const fn new(version: &'static str) -> Self { + Version { version } + } + + pub const fn as_str(&self) -> &'static str { + self.version + } + + pub fn is_dev(&self) -> bool { + self.version.contains("dev") + } +} + +pub const VERSION: Version = match option_env!("APP_VERSION") { + Some(version) => Version::new(version), + None => Version::new(DEFAULT_VERSION), +}; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_default_version() { + assert_eq!(VERSION.as_str(), DEFAULT_VERSION); + assert!(VERSION.is_dev()); + } + + #[test] + fn test_custom_version() { + const CUSTOM_VERSION: Version = Version::new("1.0.0-release"); + assert_eq!(CUSTOM_VERSION.as_str(), "1.0.0-release"); + assert!(!CUSTOM_VERSION.is_dev()); + } +}