feat: add dev suffix to version if not on a git tag (#7337)

This commit is contained in:
Colerar
2024-04-03 22:42:22 +08:00
committed by GitHub
parent 7cb05d5829
commit e6d0d7e00b
2 changed files with 22 additions and 4 deletions

View File

@ -1,15 +1,27 @@
#![allow(missing_docs)]
use std::error::Error;
use std::{env, error::Error};
use vergen::EmitBuilder;
fn main() -> Result<(), Box<dyn Error>> {
// Emit the instructions
EmitBuilder::builder()
.git_describe(false, true, None)
.git_dirty(true)
.git_sha(true)
.build_timestamp()
.cargo_features()
.cargo_target_triple()
.emit()?;
.emit_and_set()?;
let sha = env::var("VERGEN_GIT_SHA")?;
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 is_dev = is_dirty || not_on_tag;
println!("cargo:rustc-env=RETH_VERSION_SUFFIX={}", if is_dev { "-dev" } else { "" });
Ok(())
}

View File

@ -21,8 +21,13 @@ pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
/// ```text
/// 0.1.0 (defa64b2)
/// ```
pub const SHORT_VERSION: &str =
concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")");
pub const SHORT_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
" (",
env!("VERGEN_GIT_SHA"),
")"
);
/// The long version information for reth.
///
@ -44,6 +49,7 @@ pub const SHORT_VERSION: &str =
pub const LONG_VERSION: &str = const_str::concat!(
"Version: ",
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
"\n",
"Commit SHA: ",
env!("VERGEN_GIT_SHA"),