Skip to content

Commit 10d72eb

Browse files
committed
feat: add commit message and author in version metrics
1 parent 964575d commit 10d72eb

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

crates/op-rbuilder/build.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ fn main() -> Result<(), Box<dyn Error>> {
4343
.describe(false, true, None)
4444
.dirty(true)
4545
.sha(false)
46+
.commit_author_name(true)
47+
.commit_author_email(true)
48+
.commit_message(true)
4649
.build()?;
4750

4851
emitter.add_instructions(&git_builder)?;
@@ -51,6 +54,16 @@ fn main() -> Result<(), Box<dyn Error>> {
5154
let sha = env::var("VERGEN_GIT_SHA")?;
5255
let sha_short = &sha[0..7];
5356

57+
// Set short SHA
58+
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]);
59+
60+
let author_name = env::var("VERGEN_GIT_COMMIT_AUTHOR_NAME")?;
61+
let author_email = env::var("VERGEN_GIT_COMMIT_AUTHOR_EMAIL")?;
62+
let author_full = format!("{} <{}>", author_name, author_email);
63+
64+
// Set author full name
65+
println!("cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR={}", author_full);
66+
5467
let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";
5568
// > git describe --always --tags
5669
// if not on a tag: v0.2.0-beta.3-82-g1939939b
@@ -59,9 +72,6 @@ fn main() -> Result<(), Box<dyn Error>> {
5972
let version_suffix = if is_dirty || not_on_tag { "-dev" } else { "" };
6073
println!("cargo:rustc-env=OP_RBUILDER_VERSION_SUFFIX={version_suffix}");
6174

62-
// Set short SHA
63-
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]);
64-
6575
// Set the build profile
6676
let out_dir = env::var("OUT_DIR").unwrap();
6777
let profile = out_dir.rsplit(std::path::MAIN_SEPARATOR).nth(3).unwrap();
@@ -86,6 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
8696
// - The build datetime
8797
// - The build features
8898
// - The build profile
99+
// - The latest commit message and author
89100
//
90101
// Example:
91102
//
@@ -95,6 +106,7 @@ fn main() -> Result<(), Box<dyn Error>> {
95106
// Build Timestamp: 2023-05-19T01:47:19.815651705Z
96107
// Build Features: jemalloc
97108
// Build Profile: maxperf
109+
// Latest Commit: 'message' by John Doe <[email protected]>
98110
// ```
99111
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_0=Version: {pkg_version}{version_suffix}");
100112
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_1=Commit SHA: {sha}");
@@ -107,6 +119,11 @@ fn main() -> Result<(), Box<dyn Error>> {
107119
env::var("VERGEN_CARGO_FEATURES")?
108120
);
109121
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_4=Build Profile: {profile}");
122+
println!(
123+
"cargo:rustc-env=OP_RBUILDER_LONG_VERSION_5=Latest Commit: '{}' by {}",
124+
env::var("VERGEN_GIT_COMMIT_MESSAGE")?.trim_end(),
125+
author_full
126+
);
110127

111128
// The version information for op-rbuilder formatted for P2P (devp2p).
112129
// - The latest version from Cargo.toml

crates/op-rbuilder/src/metrics.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
2121
/// The build features.
2222
pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");
2323

24+
/// The latest commit message and author name and email.
25+
pub const VERGEN_GIT_AUTHOR: &str = env!("VERGEN_GIT_COMMIT_AUTHOR");
26+
pub const VERGEN_GIT_COMMIT_MESSAGE: &str = env!("VERGEN_GIT_COMMIT_MESSAGE");
27+
2428
/// The build profile name.
2529
pub const BUILD_PROFILE_NAME: &str = env!("OP_RBUILDER_BUILD_PROFILE");
2630

@@ -38,6 +42,8 @@ pub const LONG_VERSION: &str = concat!(
3842
env!("OP_RBUILDER_LONG_VERSION_3"),
3943
"\n",
4044
env!("OP_RBUILDER_LONG_VERSION_4"),
45+
"\n",
46+
env!("OP_RBUILDER_LONG_VERSION_5"),
4147
);
4248

4349
pub const VERSION: VersionInfo = VersionInfo {
@@ -47,6 +53,8 @@ pub const VERSION: VersionInfo = VersionInfo {
4753
git_sha: VERGEN_GIT_SHA,
4854
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
4955
build_profile: BUILD_PROFILE_NAME,
56+
commit_author: VERGEN_GIT_AUTHOR,
57+
commit_message: VERGEN_GIT_COMMIT_MESSAGE,
5058
};
5159

5260
/// op-rbuilder metrics
@@ -198,18 +206,24 @@ pub struct VersionInfo {
198206
pub target_triple: &'static str,
199207
/// The build profile (e.g., debug or release).
200208
pub build_profile: &'static str,
209+
/// The author of the latest commit.
210+
pub commit_author: &'static str,
211+
/// The message of the latest commit.
212+
pub commit_message: &'static str,
201213
}
202214

203215
impl VersionInfo {
204-
/// This exposes reth's version information over prometheus.
216+
/// This exposes op-rbuilder's version information over prometheus.
205217
pub fn register_version_metrics(&self) {
206-
let labels: [(&str, &str); 6] = [
218+
let labels: [(&str, &str); 8] = [
207219
("version", self.version),
208220
("build_timestamp", self.build_timestamp),
209221
("cargo_features", self.cargo_features),
210222
("git_sha", self.git_sha),
211223
("target_triple", self.target_triple),
212224
("build_profile", self.build_profile),
225+
("commit_author", self.commit_author),
226+
("commit_message", self.commit_message),
213227
];
214228

215229
let gauge = gauge!("builder_info", &labels);

0 commit comments

Comments
 (0)