mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
Use GitLab env vars to get git commit (#1831)
* use GitLab env vars to get git commit * compile_error to test it * Revert "compile_error to test it" This reverts commit 67d4782298d3cdfbe1a28231042bba6444316e8a.
This commit is contained in:
committed by
Bastian Köcher
parent
63308ac22b
commit
947a0a695b
@@ -260,6 +260,22 @@ pub struct PrometheusParams {
|
||||
#[derive(BuildInfo)]
|
||||
struct SubstrateRelayBuildInfo;
|
||||
|
||||
impl SubstrateRelayBuildInfo {
|
||||
/// Get git commit in form `<short-sha-(clean|dirty)>`.
|
||||
pub fn get_git_commit() -> String {
|
||||
// on gitlab we use images without git installed, so we can't use `rbtag` there
|
||||
// locally we don't have `CI_*` env variables, so we can't rely on them
|
||||
// => we are using `CI_*` env variables or else `rbtag`
|
||||
let maybe_sha_from_ci = option_env!("CI_COMMIT_SHORT_SHA");
|
||||
maybe_sha_from_ci
|
||||
.map(|short_sha| {
|
||||
// we assume that on CI the copy is always clean
|
||||
format!("{short_sha}-clean")
|
||||
})
|
||||
.unwrap_or_else(|| SubstrateRelayBuildInfo.get_build_commit().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl PrometheusParams {
|
||||
/// Tries to convert CLI metrics params into metrics params, used by the relay.
|
||||
pub fn into_metrics_params(self) -> anyhow::Result<relay_utils::metrics::MetricsParams> {
|
||||
@@ -273,11 +289,11 @@ impl PrometheusParams {
|
||||
};
|
||||
|
||||
let relay_version = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown");
|
||||
let relay_commit = SubstrateRelayBuildInfo.get_build_commit();
|
||||
let relay_commit = SubstrateRelayBuildInfo::get_git_commit();
|
||||
relay_utils::metrics::MetricsParams::new(
|
||||
metrics_address,
|
||||
relay_version.into(),
|
||||
relay_commit.into(),
|
||||
relay_commit,
|
||||
)
|
||||
.map_err(|e| anyhow::format_err!("{:?}", e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user