From c3a30a5a91bc8f0e3b5d8d62a4c8b8393f1bf2bb Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 7 Feb 2023 15:02:04 +0100 Subject: [PATCH 1/7] If using a prototype, display its name at Meilisearch startup --- meilisearch/build.rs | 10 ++++++++-- meilisearch/src/lib.rs | 32 ++++++++++++++++++++++++++++++++ meilisearch/src/main.rs | 5 ++++- 3 files changed, 44 insertions(+), 3 deletions(-) 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"))] { From f46cf46b8cf0929ba045d766731bd1254ef52bf1 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 7 Feb 2023 16:01:12 +0100 Subject: [PATCH 2/7] Add prototype to analytics if any --- meilisearch/src/analytics/segment_analytics.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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(), From a341c94871799db5e7bb38503f90ff0cda0a0dcb Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 9 Feb 2023 16:26:59 +0100 Subject: [PATCH 3/7] Update contributing.md --- CONTRIBUTING.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 From 9bd1cfb3a323fbac4c31ed5155175ab45e71035f Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 9 Feb 2023 16:27:18 +0100 Subject: [PATCH 4/7] Ignore -dirty flag --- meilisearch/build.rs | 2 -- meilisearch/src/lib.rs | 9 ++------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/meilisearch/build.rs b/meilisearch/build.rs index ba0cf9e70..cfc8cd63d 100644 --- a/meilisearch/build.rs +++ b/meilisearch/build.rs @@ -4,8 +4,6 @@ fn main() { 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 8b87b5a87..f17f93e74 100644 --- a/meilisearch/src/lib.rs +++ b/meilisearch/src/lib.rs @@ -435,18 +435,13 @@ pub fn configure_metrics_route(config: &mut web::ServiceConfig, enable_metrics_r /// 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 `-`. +/// 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.ends_with("-dirty") { - return None; - } - if !prototype.starts_with("prototype-") { return None; } From e1ed4bc7509e5fac65cffbdee6333ca4ee7ddea4 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Fri, 10 Feb 2023 15:48:54 +0100 Subject: [PATCH 5/7] Change Dockerfile to also pass the VERGEN_GIT_SEMVER_LIGHTWEIGHT when building --- .github/uffizzi/Dockerfile | 3 ++- .github/workflows/publish-docker-images.yml | 1 + Dockerfile | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) 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..34f52e0ed 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=$(printf "%q" ${{ github.ref_name }}) # /!\ Don't touch this without checking with Cloud team - name: Send CI information to Cloud team 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 . . From 54240db4952a78f168e7e43e8ad0294de9f72b42 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Fri, 10 Feb 2023 15:50:21 +0100 Subject: [PATCH 6/7] Add note in code so one does not forget next time --- meilisearch/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meilisearch/build.rs b/meilisearch/build.rs index cfc8cd63d..c839b6e33 100644 --- a/meilisearch/build.rs +++ b/meilisearch/build.rs @@ -1,6 +1,9 @@ use vergen::{vergen, Config, SemverKind}; fn main() { + // 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; From 49e18da23e58c10d672882db72e22f9c8f3bc1d3 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 14 Feb 2023 13:50:34 +0100 Subject: [PATCH 7/7] Do not escape tag name $() syntax is not interpreted by the Dockerfile --- .github/workflows/publish-docker-images.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-docker-images.yml b/.github/workflows/publish-docker-images.yml index 34f52e0ed..39bab4d0d 100644 --- a/.github/workflows/publish-docker-images.yml +++ b/.github/workflows/publish-docker-images.yml @@ -92,7 +92,7 @@ jobs: build-args: | COMMIT_SHA=${{ github.sha }} COMMIT_DATE=${{ steps.build-metadata.outputs.date }} - GIT_TAG=$(printf "%q" ${{ github.ref_name }}) + GIT_TAG=${{ github.ref_name }} # /!\ Don't touch this without checking with Cloud team - name: Send CI information to Cloud team