From 66e9f4925a8d25d30e1c5c69bd0d553244c500a4 Mon Sep 17 00:00:00 2001
From: Vlad <vladimir@parity.io>
Date: Mon, 12 Sep 2022 20:48:10 +0300
Subject: [PATCH] Don't run `cargo-check-benches` for `master` based downstream
 staging pipelines (#12233)

---
 substrate/.gitlab-ci.yml                      | 12 ++++++++++++
 substrate/scripts/ci/gitlab/pipeline/test.yml |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/substrate/.gitlab-ci.yml b/substrate/.gitlab-ci.yml
index 765112bfa9e..a639505b3bb 100644
--- a/substrate/.gitlab-ci.yml
+++ b/substrate/.gitlab-ci.yml
@@ -150,6 +150,18 @@ default:
     - if: $CI_PIPELINE_SOURCE == "schedule"
     - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
 
+# handle the specific case where benches could store incorrect bench data because of the downstream staging runs
+# exclude cargo-check-benches from such runs
+.test-refs-no-trigger-prs-only-check-benches:
+  rules:
+    - if: $CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "parent_pipeline"  && $CI_IMAGE =~ /staging$/ 
+      when: never
+    - if: $CI_PIPELINE_SOURCE == "pipeline"
+      when: never
+    - if: $CI_PIPELINE_SOURCE == "web"
+    - if: $CI_PIPELINE_SOURCE == "schedule"
+    - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/                         # PRs
+
 .test-refs-wasmer-sandbox:
   rules:
     - if: $CI_PIPELINE_SOURCE == "web"
diff --git a/substrate/scripts/ci/gitlab/pipeline/test.yml b/substrate/scripts/ci/gitlab/pipeline/test.yml
index 50916a37fcf..7be445b0bca 100644
--- a/substrate/scripts/ci/gitlab/pipeline/test.yml
+++ b/substrate/scripts/ci/gitlab/pipeline/test.yml
@@ -59,7 +59,7 @@ cargo-check-benches:
     CI_JOB_NAME:                   "cargo-check-benches"
   extends:
     - .docker-env
-    - .test-refs
+    - .test-refs-no-trigger-prs-only-check-benches
     - .collect-artifacts
     - .pipeline-stopper-artifacts
   before_script:
-- 
GitLab