fix: use 8 byte SHA in getClientVersionV1 (#9137)

This commit is contained in:
Michael Sproul
2024-06-27 21:03:40 +10:00
committed by GitHub
parent 793aa85269
commit e09ed75a9b
7 changed files with 66 additions and 20 deletions

View File

@ -58,7 +58,7 @@ eyre.workspace = true
clap = { workspace = true, features = ["derive"] }
humantime.workspace = true
thiserror.workspace = true
const-str = "0.5.6"
const_format.workspace = true
rand.workspace = true
derive_more.workspace = true
once_cell.workspace = true

View File

@ -8,19 +8,20 @@ fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder()
.git_describe(false, true, None)
.git_dirty(true)
.git_sha(true)
.git_sha(false)
.build_timestamp()
.cargo_features()
.cargo_target_triple()
.emit_and_set()?;
let sha = env::var("VERGEN_GIT_SHA")?;
let sha_short = &sha[0..7];
let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";
// > git describe --always --tags
// if not on a tag: v0.2.0-beta.3-82-g1939939b
// if on a tag: v0.2.0-beta.3
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha}"));
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha_short}"));
let is_dev = is_dirty || not_on_tag;
println!("cargo:rustc-env=RETH_VERSION_SUFFIX={}", if is_dev { "-dev" } else { "" });
Ok(())

View File

@ -1,13 +1,13 @@
//! This exposes reth's version information over prometheus.
use crate::version::build_profile_name;
use crate::version::{build_profile_name, VERGEN_GIT_SHA};
use metrics::gauge;
const LABELS: [(&str, &str); 6] = [
("version", env!("CARGO_PKG_VERSION")),
("build_timestamp", env!("VERGEN_BUILD_TIMESTAMP")),
("cargo_features", env!("VERGEN_CARGO_FEATURES")),
("git_sha", env!("VERGEN_GIT_SHA")),
("git_sha", VERGEN_GIT_SHA),
("target_triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
("build_profile", build_profile_name()),
];

View File

@ -11,8 +11,11 @@ pub const NAME_CLIENT: &str = "Reth";
/// The latest version from Cargo.toml.
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
/// The short SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA");
/// The full SHA of the latest commit.
pub const VERGEN_GIT_SHA_LONG: &str = env!("VERGEN_GIT_SHA");
/// The 8 character short SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = const_format::str_index!(VERGEN_GIT_SHA_LONG, ..8);
/// The build timestamp.
pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
@ -27,11 +30,11 @@ pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
/// ```text
/// 0.1.0 (defa64b2)
/// ```
pub const SHORT_VERSION: &str = concat!(
pub const SHORT_VERSION: &str = const_format::concatcp!(
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
" (",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA,
")"
);
@ -52,13 +55,13 @@ pub const SHORT_VERSION: &str = concat!(
/// Build Features: jemalloc
/// Build Profile: maxperf
/// ```
pub const LONG_VERSION: &str = const_str::concat!(
pub const LONG_VERSION: &str = const_format::concatcp!(
"Version: ",
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
"\n",
"Commit SHA: ",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA_LONG,
"\n",
"Build Timestamp: ",
env!("VERGEN_BUILD_TIMESTAMP"),
@ -81,11 +84,11 @@ pub const LONG_VERSION: &str = const_str::concat!(
/// reth/v{major}.{minor}.{patch}-{sha1}/{target}
/// ```
/// e.g.: `reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin`
pub(crate) const P2P_CLIENT_VERSION: &str = concat!(
pub(crate) const P2P_CLIENT_VERSION: &str = const_format::concatcp!(
"reth/v",
env!("CARGO_PKG_VERSION"),
"-",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA,
"/",
env!("VERGEN_CARGO_TARGET_TRIPLE")
);
@ -118,9 +121,13 @@ pub(crate) const fn build_profile_name() -> &'static str {
// We split on the path separator of the *host* machine, which may be different from
// `std::path::MAIN_SEPARATOR_STR`.
const OUT_DIR: &str = env!("OUT_DIR");
const SEP: char = if const_str::contains!(OUT_DIR, "/") { '/' } else { '\\' };
let parts = const_str::split!(OUT_DIR, SEP);
parts[parts.len() - 4]
let unix_parts = const_format::str_split!(OUT_DIR, '/');
if unix_parts.len() >= 4 {
unix_parts[unix_parts.len() - 4]
} else {
let win_parts = const_format::str_split!(OUT_DIR, '\\');
win_parts[win_parts.len() - 4]
}
}
#[cfg(test)]