From b7fe56acbb0d7b096c6156087d788ccb191b31e1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 31 Jan 2023 11:07:31 +0300 Subject: [PATCH 1/4] use GitLab env vars to get git commit --- relays/bin-substrate/src/cli/mod.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 17d0262b21..74ca82d6d9 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -260,6 +260,22 @@ pub struct PrometheusParams { #[derive(BuildInfo)] struct SubstrateRelayBuildInfo; +impl SubstrateRelayBuildInfo { + /// Get git commit in form ``. + 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!("{}-clean", short_sha) + }) + .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 { @@ -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)) } From 67d4782298d3cdfbe1a28231042bba6444316e8a Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 31 Jan 2023 11:12:08 +0300 Subject: [PATCH 2/4] compile_error to test it --- relays/bin-substrate/src/cli/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 74ca82d6d9..82fc5a66af 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -267,6 +267,7 @@ impl SubstrateRelayBuildInfo { // 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"); + compile_error!(env!("CI_COMMIT_SHORT_SHA")); // TODO: remove me, just for test maybe_sha_from_ci .map(|short_sha| { // we assume that on CI the copy is always clean From 25f9608869c045ab75fed7473ac658d9f4c15dd1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 31 Jan 2023 11:23:18 +0300 Subject: [PATCH 3/4] Revert "compile_error to test it" This reverts commit 67d4782298d3cdfbe1a28231042bba6444316e8a. --- relays/bin-substrate/src/cli/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 82fc5a66af..74ca82d6d9 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -267,7 +267,6 @@ impl SubstrateRelayBuildInfo { // 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"); - compile_error!(env!("CI_COMMIT_SHORT_SHA")); // TODO: remove me, just for test maybe_sha_from_ci .map(|short_sha| { // we assume that on CI the copy is always clean From 54d31cec2145c1ceb3ff5bab744dde0382f10815 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 31 Jan 2023 11:31:43 +0300 Subject: [PATCH 4/4] clippy --- relays/bin-substrate/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relays/bin-substrate/src/cli/mod.rs b/relays/bin-substrate/src/cli/mod.rs index 74ca82d6d9..a5b9074406 100644 --- a/relays/bin-substrate/src/cli/mod.rs +++ b/relays/bin-substrate/src/cli/mod.rs @@ -270,7 +270,7 @@ impl SubstrateRelayBuildInfo { maybe_sha_from_ci .map(|short_sha| { // we assume that on CI the copy is always clean - format!("{}-clean", short_sha) + format!("{short_sha}-clean") }) .unwrap_or_else(|| SubstrateRelayBuildInfo.get_build_commit().into()) }