diff --git a/meilisearch/build.rs b/meilisearch/build.rs index e2207561b..ba0cf9e70 100644 --- a/meilisearch/build.rs +++ b/meilisearch/build.rs @@ -1,7 +1,13 @@ -use vergen::{vergen, Config}; +use vergen::{vergen, Config, SemverKind}; fn main() { - if let Err(e) = vergen(Config::default()) { + let mut config = Config::default(); + // allow using non-annotated tags + *config.git_mut().semver_kind_mut() = SemverKind::Lightweight; + // add -dirty suffix when we're not right on the tag + *config.git_mut().semver_dirty_mut() = Some("-dirty"); + + if let Err(e) = vergen(config) { println!("cargo:warning=vergen: {}", e); } diff --git a/meilisearch/src/lib.rs b/meilisearch/src/lib.rs index 7a7555659..8b87b5a87 100644 --- a/meilisearch/src/lib.rs +++ b/meilisearch/src/lib.rs @@ -427,3 +427,35 @@ pub fn configure_metrics_route(config: &mut web::ServiceConfig, enable_metrics_r ); } } + +/// Parses the output of +/// [`VERGEN_GIT_SEMVER_LIGHTWEIGHT`](https://docs.rs/vergen/latest/vergen/struct.Git.html#instructions) +/// as a prototype name. +/// +/// Returns `Some(prototype_name)` if the following conditions are met on this value: +/// +/// 1. starts with `prototype-`, +/// 2. does not end with `dirty-`, +/// 3. ends with `-`, +/// 4. does not end with `-`. +/// +/// Otherwise, returns `None`. +pub fn prototype_name() -> Option<&'static str> { + let prototype: &'static str = option_env!("VERGEN_GIT_SEMVER_LIGHTWEIGHT")?; + + if prototype.ends_with("-dirty") { + return None; + } + + if !prototype.starts_with("prototype-") { + return None; + } + + let mut rsplit_prototype = prototype.rsplit('-'); + // last component MUST be a number + rsplit_prototype.next()?.parse::().ok()?; + // before than last component SHALL NOT be a number + rsplit_prototype.next()?.parse::().err()?; + + Some(prototype) +} diff --git a/meilisearch/src/main.rs b/meilisearch/src/main.rs index b78362ec1..d12539e20 100644 --- a/meilisearch/src/main.rs +++ b/meilisearch/src/main.rs @@ -8,7 +8,7 @@ use actix_web::web::Data; use actix_web::HttpServer; use index_scheduler::IndexScheduler; use meilisearch::analytics::Analytics; -use meilisearch::{analytics, create_app, setup_meilisearch, Opt}; +use meilisearch::{analytics, create_app, prototype_name, setup_meilisearch, Opt}; use meilisearch_auth::{generate_master_key, AuthController, MASTER_KEY_MIN_SIZE}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -137,6 +137,9 @@ pub fn print_launch_resume( eprintln!("Commit SHA:\t\t{:?}", commit_sha.to_string()); eprintln!("Commit date:\t\t{:?}", commit_date.to_string()); eprintln!("Package version:\t{:?}", env!("CARGO_PKG_VERSION").to_string()); + if let Some(prototype) = prototype_name() { + eprintln!("Prototype:\t\t{:?}", prototype); + } #[cfg(all(not(debug_assertions), feature = "analytics"))] {