Skip to content

Commit 6dbce72

Browse files
authored
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 67d4782.
1 parent b1a8161 commit 6dbce72

File tree

1 file changed

+18
-2
lines changed
  • relays/bin-substrate/src/cli

1 file changed

+18
-2
lines changed

relays/bin-substrate/src/cli/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ pub struct PrometheusParams {
260260
#[derive(BuildInfo)]
261261
struct SubstrateRelayBuildInfo;
262262

263+
impl SubstrateRelayBuildInfo {
264+
/// Get git commit in form `<short-sha-(clean|dirty)>`.
265+
pub fn get_git_commit() -> String {
266+
// on gitlab we use images without git installed, so we can't use `rbtag` there
267+
// locally we don't have `CI_*` env variables, so we can't rely on them
268+
// => we are using `CI_*` env variables or else `rbtag`
269+
let maybe_sha_from_ci = option_env!("CI_COMMIT_SHORT_SHA");
270+
maybe_sha_from_ci
271+
.map(|short_sha| {
272+
// we assume that on CI the copy is always clean
273+
format!("{short_sha}-clean")
274+
})
275+
.unwrap_or_else(|| SubstrateRelayBuildInfo.get_build_commit().into())
276+
}
277+
}
278+
263279
impl PrometheusParams {
264280
/// Tries to convert CLI metrics params into metrics params, used by the relay.
265281
pub fn into_metrics_params(self) -> anyhow::Result<relay_utils::metrics::MetricsParams> {
@@ -273,11 +289,11 @@ impl PrometheusParams {
273289
};
274290

275291
let relay_version = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown");
276-
let relay_commit = SubstrateRelayBuildInfo.get_build_commit();
292+
let relay_commit = SubstrateRelayBuildInfo::get_git_commit();
277293
relay_utils::metrics::MetricsParams::new(
278294
metrics_address,
279295
relay_version.into(),
280-
relay_commit.into(),
296+
relay_commit,
281297
)
282298
.map_err(|e| anyhow::format_err!("{:?}", e))
283299
}

0 commit comments

Comments
 (0)