Skip to content

feat(cli): enhance --version outputs for merod cli #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c7106f0
feat: improved --version outputs
dotandev May 10, 2025
eb60540
Merge branch 'calimero-network:master' into feat/cli
dotandev May 13, 2025
c71126f
Merge branch 'calimero-network:master' into feat/cli
dotandev May 17, 2025
ae6af43
test build with CI
dotandev May 17, 2025
37086ca
test build with CI
dotandev May 17, 2025
aabee00
test build with CI
dotandev May 17, 2025
32791d4
test build with CI
dotandev May 17, 2025
1185b8b
fixed rootcommad import error
dotandev May 17, 2025
ee7a1d6
remove breaking tests
dotandev May 17, 2025
2d49a0b
fixed tests to all pass
dotandev May 17, 2025
ec33bfd
Resolve merge conflicts between feat/cli and master
dotandev May 17, 2025
c0b50a3
changed cargo.lock to master
dotandev May 17, 2025
ad4afc0
formatted code with nightly
dotandev May 17, 2025
926582e
Merge branch 'master' into feat/cli
dotandev May 19, 2025
e57e837
Local changes before pulling feat/cli
dotandev May 20, 2025
d886b05
Merge branch 'feat/cli' of https://github.com/dotandev/core into feat…
dotandev May 20, 2025
56a684a
testing ci
dotandev May 20, 2025
cfebee9
testing ci
dotandev May 20, 2025
373e18a
updated cargo.lock
dotandev May 20, 2025
d2bcbae
updated cargo.lock
dotandev May 20, 2025
270a070
updated cargo.lock
dotandev May 20, 2025
a79641b
fixed test error
dotandev May 20, 2025
f06de4d
fixed format error
dotandev May 20, 2025
1428cf2
Merge branch 'calimero-network:master' into feat/cli
dotandev May 21, 2025
8c2e9e1
state before pull
dotandev May 21, 2025
63d6c69
Merge branch 'feat/cli' of https://github.com/dotandev/core into feat…
dotandev May 21, 2025
d564ae8
WIP: update CLI and versioning
dotandev May 29, 2025
00fb5fd
Merge branch 'master' into feat/cli
dotandev May 29, 2025
97b8e1c
Merge branch 'calimero-network:master' into feat/cli
dotandev Jun 9, 2025
d34cf4a
fixes ranging from imports to the .toml file
dotandev Jun 9, 2025
cc4e7fd
fixes ranging from imports to the .toml file
dotandev Jun 9, 2025
e817442
fixes ranging from imports to the .toml file
dotandev Jun 9, 2025
6b50d30
fixes version in merod
dotandev Jun 9, 2025
d9b8ee3
fixes version in merod
dotandev Jun 9, 2025
7f6a1cc
fixed format error
dotandev Jun 9, 2025
4a8fe49
fixed imports and changed workflow
dotandev Jun 9, 2025
b977328
fixed imports and changed workflow
dotandev Jun 9, 2025
5c451d7
revisions
miraclx Jun 9, 2025
70d99e0
account for working tree changes
miraclx Jun 9, 2025
67cc653
Merge branch 'master' into feat/cli
dotandev Jun 9, 2025
c066076
update version check logic, print to stderr
miraclx Jun 9, 2025
3d038e7
Merge branch 'master' into feat/cli
miraclx Jun 9, 2025
2cbcb9e
fix CI
miraclx Jun 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"./crates/store/impl/rocksdb",
"./crates/store/blobs",
"./crates/utils/actix",
"./crates/version",

"./apps/kv-store",

Expand Down Expand Up @@ -169,6 +170,7 @@ calimero-store-rocksdb = { path = "./crates/store/impl/rocksdb" }
calimero-blobstore = { path = "./crates/store/blobs" }
e2e-tests = { path = "./e2e-tests" }
calimero-utils-actix = { path = "./crates/utils/actix" }
calimero-version = { path = "./crates/version" }

kv-store = { path = "./apps/kv-store" }

Expand Down
1 change: 1 addition & 0 deletions crates/meroctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ calimero-config.workspace = true
calimero-context-config.workspace = true
calimero-primitives.workspace = true
calimero-server-primitives.workspace = true
calimero-version.workspace = true

[lints]
workspace = true
3 changes: 2 additions & 1 deletion crates/meroctl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod proxy;

use app::AppCommand;
use call::CallCommand;
use calimero_version::CalimeroVersion;
use context::ContextCommand;
use peers::PeersCommand;
use proxy::ProxyCommand;
Expand All @@ -38,7 +39,7 @@ pub const EXAMPLES: &str = r"
";

#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
#[command(author, version = CalimeroVersion::current_str(), about, long_about = None)]
#[command(after_help = concatcp!(
"Environment variables:\n",
" CALIMERO_HOME Directory for config and data\n\n",
Expand Down
1 change: 1 addition & 0 deletions crates/merod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ calimero-network-primitives.workspace = true
calimero-server = { workspace = true, features = ["jsonrpc", "websocket", "admin"] }
calimero-store.workspace = true
calimero-store-rocksdb.workspace = true
calimero-version.workspace = true
calimero-utils-actix.workspace = true

[lints]
Expand Down
3 changes: 2 additions & 1 deletion crates/merod/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
use const_format::concatcp;
use eyre::Result as EyreResult;
use calimero_version::CalimeroVersion;

use crate::defaults;

Expand Down Expand Up @@ -31,7 +32,7 @@ pub const EXAMPLES: &str = r"
";

#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
#[command(author, version = CalimeroVersion::current_str(), about, long_about = None)]
#[command(after_help = concatcp!(
"Environment variables:\n",
" CALIMERO_HOME Directory for config and data\n\n",
Expand Down
11 changes: 11 additions & 0 deletions crates/version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "calimero-version"
version = "0.6.0"
authors.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[build-dependencies]
rustc_version = "0.4"
eyre = "0.6"
54 changes: 54 additions & 0 deletions crates/version/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::process::Command;
use eyre::{eyre, Result as EyreResult};

fn main() {
if let Err(err) = try_main() {
eprintln!("build.rs error: {err}");
std::process::exit(1);
}
}

fn try_main() -> EyreResult<()> {
let git_describe = run_command(
"git",
&[
"describe",
"--always",
"--dirty=-modified",
"--tags",
"--match",
"[0-9]*",
],
)?;

let git_commit = run_command("git", &["rev-parse", "--short", "HEAD"])?;

let rustc_version = rustc_version::version()
.map(|v| v.to_string())
.unwrap_or_else(|_| "unknown".to_string());

println!("cargo:rustc-env=CALIMERO_BUILD={}", git_describe.trim());
println!("cargo:rustc-env=CALIMERO_COMMIT={}", git_commit.trim());
println!(
"cargo:rustc-env=CALIMERO_RUSTC_VERSION={}",
rustc_version.trim()
);

Ok(())
}

fn run_command(command: &str, args: &[&str]) -> EyreResult<String> {
let output = Command::new(command)
.args(args)
.output()
.map_err(|e| eyre!("failed to execute `{}`: {}", command, e))?;

if !output.status.success() {
return Err(eyre!("`{}` failed with status: {}", command, output.status));
}

let stdout = String::from_utf8(output.stdout)
.map_err(|e| eyre!("invalid UTF-8 output from `{}`: {}", command, e))?;

Ok(stdout)
}
43 changes: 43 additions & 0 deletions crates/version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::borrow::Cow;
use std::fmt;
use std::sync::LazyLock;

#[cfg(test)]
mod tests;

static CURRENT: LazyLock<CalimeroVersion<'static>> = LazyLock::new(|| CalimeroVersion {
release: env!("CARGO_PKG_VERSION").into(),
build: env!("CALIMERO_BUILD").into(),
commit: env!("CALIMERO_COMMIT").into(),
rustc: env!("CALIMERO_RUSTC_VERSION").into(),
});

static CURRENT_STRING: LazyLock<String> = LazyLock::new(|| CURRENT.to_string());

#[derive(Clone)]
pub struct CalimeroVersion<'a> {
pub release: Cow<'a, str>,
pub build: Cow<'a, str>,
pub commit: Cow<'a, str>,
pub rustc: Cow<'a, str>,
}

impl CalimeroVersion<'static> {
pub fn current() -> Self {
CURRENT.clone()
}

pub fn current_str() -> &'static str {
&*CURRENT_STRING
}
}

impl fmt::Display for CalimeroVersion<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(release {}) (build {}) (commit {}) (rustc {})",
self.release, self.build, self.commit, self.rustc,
)
}
}
47 changes: 47 additions & 0 deletions crates/version/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::CalimeroVersion;

#[test]
fn version_info_contains_crate_version() {
let info = CalimeroVersion::current_str();
let expected = env!("CARGO_PKG_VERSION");
assert!(
info.contains(expected),
"version_info does not contain crate version: expected `{}` in `{}`",
expected,
info
);
}

#[test]
fn version_info_contains_commit_hash() {
let info = CalimeroVersion::current_str();
let expected = env!("CALIMERO_COMMIT");
assert!(
info.contains(expected),
"version_info does not contain commit hash: expected `{}` in `{}`",
expected,
info
);
}

#[test]
fn version_info_contains_rustc_version() {
let info = CalimeroVersion::current_str();
let expected = env!("CALIMERO_RUSTC_VERSION");
assert!(
info.contains(expected),
"version_info does not contain rustc version: expected `{}` in `{}`",
expected,
info
);
}

#[test]
fn version_info_has_no_unknown_values() {
let info = CalimeroVersion::current_str();
assert!(
!info.contains("unknown"),
"version_info contains 'unknown': {}",
info
);
}
Loading