File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
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 {
260
260
#[ derive( BuildInfo ) ]
261
261
struct SubstrateRelayBuildInfo ;
262
262
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
+
263
279
impl PrometheusParams {
264
280
/// Tries to convert CLI metrics params into metrics params, used by the relay.
265
281
pub fn into_metrics_params ( self ) -> anyhow:: Result < relay_utils:: metrics:: MetricsParams > {
@@ -273,11 +289,11 @@ impl PrometheusParams {
273
289
} ;
274
290
275
291
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 ( ) ;
277
293
relay_utils:: metrics:: MetricsParams :: new (
278
294
metrics_address,
279
295
relay_version. into ( ) ,
280
- relay_commit. into ( ) ,
296
+ relay_commit,
281
297
)
282
298
. map_err ( |e| anyhow:: format_err!( "{:?}" , e) )
283
299
}
You can’t perform that action at this time.
0 commit comments