Skip to content

Commit decd330

Browse files
authored
Merge pull request RedisJSON#520 from RedisJSON/omer_gitsha
Print git sha to module log on init
2 parents e6da70b + b8e8c28 commit decd330

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
// Expose GIT_SHA env var
5+
let git_sha = Command::new("git")
6+
.args(&["rev-parse", "--short", "HEAD"])
7+
.output();
8+
if let Ok(sha) = git_sha {
9+
let sha = String::from_utf8(sha.stdout).unwrap();
10+
println!("cargo:rustc-env=GIT_SHA={}", sha);
11+
}
12+
// Expose GIT_BRANCH env var
13+
let git_branch = Command::new("git")
14+
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
15+
.output();
16+
if let Ok(branch) = git_branch {
17+
let branch = String::from_utf8(branch.stdout).unwrap();
18+
println!("cargo:rustc-env=GIT_BRANCH={}", branch);
19+
}
20+
}

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub mod manager;
2727
mod nodevisitor;
2828
pub mod redisjson;
2929

30+
pub const GIT_SHA: Option<&'static str> = std::option_env!("GIT_SHA");
31+
pub const GIT_BRANCH: Option<&'static str> = std::option_env!("GIT_BRANCH");
32+
3033
pub const REDIS_JSON_TYPE_VERSION: i32 = 3;
3134

3235
pub static REDIS_JSON_TYPE: RedisType = RedisType::new(
@@ -400,6 +403,11 @@ macro_rules! redis_json_module_create {(
400403
}
401404

402405
fn intialize(ctx: &Context, args: &Vec<RedisString>) -> Status {
406+
ctx.log_notice(&format!("version: {} git sha: {} branch: {}",
407+
$version,
408+
match GIT_SHA { Some(val) => val, _ => "unknown"},
409+
match GIT_BRANCH { Some(val) => val, _ => "unknown"},
410+
));
403411
export_shared_api(ctx);
404412
ctx.set_module_options(ModuleOptions::HANDLE_IO_ERRORS);
405413
ctx.log_notice("Enabled diskless replication");

0 commit comments

Comments
 (0)