diff --git a/.github/uffizzi/Dockerfile b/.github/uffizzi/Dockerfile index ae2b8231e..57ee4aa8d 100644 --- a/.github/uffizzi/Dockerfile +++ b/.github/uffizzi/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /meilisearch ARG COMMIT_SHA ARG COMMIT_DATE -ENV COMMIT_SHA=${COMMIT_SHA} COMMIT_DATE=${COMMIT_DATE} +ARG GIT_TAG +ENV COMMIT_SHA=${COMMIT_SHA} COMMIT_DATE=${COMMIT_DATE} VERGEN_GIT_SEMVER_LIGHTWEIGHT=${GIT_TAG} ENV RUSTFLAGS="-C target-feature=-crt-static" COPY . . diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index 5d1b50f79..39bab4d0d 100644 --- a/.github/workflows/publish-docker-images.yml +++ b/.github/workflows/publish-docker-images.yml @@ -92,6 +92,7 @@ jobs: build-args: | COMMIT_SHA=${{ github.sha }} COMMIT_DATE=${{ steps.build-metadata.outputs.date }} + GIT_TAG=${{ github.ref_name }} # /!\ Don't touch this without checking with Cloud team - name: Send CI information to Cloud team diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 19e1d9372..31fe45a94 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,15 +121,19 @@ The full Meilisearch release process is described in [this guide](https://github Depending on the developed feature, you might need to provide a prototyped version of Meilisearch to make it easier to test by the users. The prototype name must follow this convention: `prototype-X-Y` where -- `X` is the feature name formatted in `kebab-case` +- `X` is the feature name formatted in `kebab-case`. It should not end with a single number. - `Y` is the version of the prototype, starting from `0`. -Example: `prototype-auto-resize-0`. +✅ Example: `prototype-auto-resize-0`.
+❌ Bad example: `auto-resize-0`: lacks the `prototype` prefix.
+❌ Bad example: `prototype-auto-resize`: lacks the version suffix.
+❌ Bad example: `prototype-auto-resize-0-0`: feature name ends with a single number. Steps to create a prototype: 1. In your terminal, go to the last commit of your branch (the one you want to provide as a prototype). 2. Create a tag following the convention: `git tag prototype-X-Y` +3. Run Meilisearch and check that its launch summary features a line: `Prototype: prototype-X-Y` (you may need to switch branches and back after tagging for this to work). 3. Push the tag: `git push origin prototype-X-Y` 4. Check the [Docker CI](https://github.com/meilisearch/meilisearch/actions/workflows/publish-docker-images.yml) is now running. @@ -138,7 +142,7 @@ More information about [how to run Meilisearch with Docker](https://docs.meilise ⚙️ However, no binaries will be created. If the users do not use Docker, they can go to the `prototype-X-Y` tag in the Meilisearch repository and compile from the source code. -⚠️ When sharing a prototype with users, prevent them from using it in production. Prototypes are only for test purposes. +⚠️ When sharing a prototype with users, remind them to not use it in production. Prototypes are solely for test purposes. ### Release assets diff --git a/Dockerfile b/Dockerfile index 6846fdad7..70950f338 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /meilisearch ARG COMMIT_SHA ARG COMMIT_DATE -ENV VERGEN_GIT_SHA=${COMMIT_SHA} VERGEN_GIT_COMMIT_TIMESTAMP=${COMMIT_DATE} +ARG GIT_TAG +ENV VERGEN_GIT_SHA=${COMMIT_SHA} VERGEN_GIT_COMMIT_TIMESTAMP=${COMMIT_DATE} VERGEN_GIT_SEMVER_LIGHTWEIGHT=${GIT_TAG} ENV RUSTFLAGS="-C target-feature=-crt-static" COPY . . diff --git a/meilisearch/build.rs b/meilisearch/build.rs index e2207561b..c839b6e33 100644 --- a/meilisearch/build.rs +++ b/meilisearch/build.rs @@ -1,7 +1,14 @@ -use vergen::{vergen, Config}; +use vergen::{vergen, Config, SemverKind}; fn main() { - if let Err(e) = vergen(Config::default()) { + // Note: any code that needs VERGEN_ environment variables should take care to define them manually in the Dockerfile and pass them + // in the corresponding GitHub workflow (publish_docker.yml). + // This is due to the Dockerfile building the binary outside of the git directory. + let mut config = Config::default(); + // allow using non-annotated tags + *config.git_mut().semver_kind_mut() = SemverKind::Lightweight; + + if let Err(e) = vergen(config) { println!("cargo:warning=vergen: {}", e); } diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 21b6696e7..566770646 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -401,12 +401,19 @@ impl Segment { if let Ok(stats) = create_all_stats(index_scheduler.into(), auth_controller, &SearchRules::default()) { + // Replace the version number with the prototype name if any. + let version = if let Some(prototype) = crate::prototype_name() { + prototype + } else { + env!("CARGO_PKG_VERSION") + }; + let _ = self .batcher .push(Identify { context: Some(json!({ "app": { - "version": env!("CARGO_PKG_VERSION").to_string(), + "version": version.to_string(), }, })), user: self.user.clone(), diff --git a/meilisearch/src/lib.rs b/meilisearch/src/lib.rs index 7a7555659..f17f93e74 100644 --- a/meilisearch/src/lib.rs +++ b/meilisearch/src/lib.rs @@ -427,3 +427,30 @@ 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. ends with `-`, +/// 3. 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.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"))] {