File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
bridges/relays/bin-substrate/src/cli Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,22 @@ pub struct PrometheusParams {
260260#[ derive( BuildInfo ) ]
261261struct 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+
263279impl 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 }
You can’t perform that action at this time.
0 commit comments