From e35b17a0ecdfe9788ae7f849e87659bca1c8a5b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Coutable?= <remy@rymai.me>
Date: Thu, 25 May 2023 10:23:12 +0000
Subject: [PATCH] Remove references to the E2E nightly project
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rémy Coutable <remy@rymai.me>
---
 .../end_to_end/execution_context_selection.md |  8 ++--
 .../testing_guide/end_to_end/index.md         |  4 +-
 ...unning_tests_that_require_special_setup.md |  2 -
 qa/.confiner/master.yml                       | 19 ---------
 qa/.confiner/nightly.yml                      | 19 ---------
 qa/qa/runtime/env.rb                          |  4 ++
 qa/qa/specs/helpers/context_selector.rb       |  8 +++-
 .../specs/helpers/context_selector_spec.rb    | 41 +++++++++++++++++++
 8 files changed, 58 insertions(+), 47 deletions(-)
 delete mode 100644 qa/.confiner/nightly.yml

diff --git a/doc/development/testing_guide/end_to_end/execution_context_selection.md b/doc/development/testing_guide/end_to_end/execution_context_selection.md
index 4d83884f4d0d6..0082bb6ee239f 100644
--- a/doc/development/testing_guide/end_to_end/execution_context_selection.md
+++ b/doc/development/testing_guide/end_to_end/execution_context_selection.md
@@ -44,8 +44,8 @@ Matches use:
 | `gitlab.com and staging.gitlab.com`      | `only: { subdomain: /(staging.)?/, domain: 'gitlab' }` | `(staging.)?gitlab.com` |
 | `dev.gitlab.org`                         | `only: { tld: '.org', domain: 'gitlab', subdomain: 'dev' }` | `(dev).gitlab.org` |
 | `staging.gitlab.com and domain.gitlab.com` | `only: { subdomain: %i[staging domain] }` | `(staging\|domain).+.com`             |
-| The `nightly` pipeline                     | `only: { pipeline: :nightly }` | "nightly" |
-| The `nightly` and `canary` pipelines | `only: { pipeline: [:nightly, :canary] }` | ["nightly"](https://gitlab.com/gitlab-org/quality/nightly) and ["canary"](https://gitlab.com/gitlab-org/quality/canary) |
+| The `nightly` pipeline                     | `only: { pipeline: :nightly }` | ["nightly scheduled pipeline"](https://gitlab.com/gitlab-org/gitlab/-/pipeline_schedules) |
+| The `nightly` and `canary` pipelines | `only: { pipeline: [:nightly, :canary] }` | ["nightly scheduled pipeline"](https://gitlab.com/gitlab-org/gitlab/-/pipeline_schedules) and ["canary"](https://gitlab.com/gitlab-org/quality/canary) |
 | The `ee:instance` job | `only: { job: 'ee:instance' }` | The `ee:instance` job in any pipeline |
 | Any `quarantine` job | `only: { job: '.*quarantine' }` | Any job ending in `quarantine` in any pipeline |
 | Any run where condition evaluates to a truthy value | `only: { condition: -> { ENV['TEST_ENV'] == 'true' } }` | Any run where `TEST_ENV` is set to true
@@ -87,8 +87,8 @@ Matches use:
 | `gitlab.com and staging.gitlab.com`      | `except: { subdomain: /(staging.)?/, domain: 'gitlab' }` | `(staging.)?gitlab.com` |
 | `dev.gitlab.org`                         | `except: { tld: '.org', domain: 'gitlab', subdomain: 'dev' }` | `(dev).gitlab.org` |
 | `staging.gitlab.com and domain.gitlab.com` | `except: { subdomain: %i[staging domain] }` | `(staging\|domain).+.com`             |
-| The `nightly` pipeline                     | `except: { pipeline: :nightly }` | ["nightly"](https://gitlab.com/gitlab-org/quality/nightly) |
-| The `nightly` and `canary` pipelines | `except: { pipeline: [:nightly, :canary] }` | ["nightly"](https://gitlab.com/gitlab-org/quality/nightly) and ["canary"](https://gitlab.com/gitlab-org/quality/canary) |
+| The `nightly` pipeline                     | `only: { pipeline: :nightly }` | ["nightly scheduled pipeline"](https://gitlab.com/gitlab-org/gitlab/-/pipeline_schedules) |
+| The `nightly` and `canary` pipelines | `only: { pipeline: [:nightly, :canary] }` | ["nightly scheduled pipeline"](https://gitlab.com/gitlab-org/gitlab/-/pipeline_schedules) and ["canary"](https://gitlab.com/gitlab-org/quality/canary) |
 | The `ee:instance` job | `except: { job: 'ee:instance' }` | The `ee:instance` job in any pipeline |
 | Any `quarantine` job | `except: { job: '.*quarantine' }` | Any job ending in `quarantine` in any pipeline |
 | Any run except where condition evaluates to a truthy value | `except: { condition: -> { ENV['TEST_ENV'] == 'true' } }` | Any run where `TEST_ENV` is not set to true
diff --git a/doc/development/testing_guide/end_to_end/index.md b/doc/development/testing_guide/end_to_end/index.md
index 7932d4131f3dd..adf679c44a2e6 100644
--- a/doc/development/testing_guide/end_to_end/index.md
+++ b/doc/development/testing_guide/end_to_end/index.md
@@ -21,8 +21,8 @@ using the [GitLab QA orchestrator](https://gitlab.com/gitlab-org/gitlab-qa) tool
 ### Testing nightly builds
 
 We run scheduled pipelines each night to test nightly builds created by Omnibus.
-You can find these pipelines at <https://gitlab.com/gitlab-org/quality/nightly/pipelines>
-(requires the Developer role). Results are reported in the `#qa-nightly` Slack channel.
+You can find these pipelines at <https://gitlab.com/gitlab-org/gitlab/-/pipeline_schedules>
+(requires the Developer role). Results are reported in the `#qa-master` Slack channel.
 
 ### Testing staging
 
diff --git a/doc/development/testing_guide/end_to_end/running_tests_that_require_special_setup.md b/doc/development/testing_guide/end_to_end/running_tests_that_require_special_setup.md
index adf7bccb7fbe0..146ad95b25531 100644
--- a/doc/development/testing_guide/end_to_end/running_tests_that_require_special_setup.md
+++ b/doc/development/testing_guide/end_to_end/running_tests_that_require_special_setup.md
@@ -428,8 +428,6 @@ For instructions on how to run these tests using the `gitlab-qa` gem, please ref
 
 Tests that are tagged with `:mobile` can be run against specified mobile devices using cloud emulator/simulator services.
 
-These tests run in the [nightly pipeline](https://gitlab.com/gitlab-org/quality/nightly/-/pipelines) in the `ce:remote_mobile_safari` job.
-
 ### How to run mobile tests with Sauce Labs
 
 Running directly against an environment like staging is not recommended because Sauce Labs test logs expose credentials. Therefore, it is best practice and the default to use a tunnel.
diff --git a/qa/.confiner/master.yml b/qa/.confiner/master.yml
index e6fc3e6874773..f58ea5de0172b 100644
--- a/qa/.confiner/master.yml
+++ b/qa/.confiner/master.yml
@@ -13,22 +13,3 @@
       ref: master
   actions:
     - quarantine
-
-- name: Dequarantine E2E tests in Master that pass consistently
-  plugin:
-    name: gitlab # https://gitlab.com/gitlab-org/quality/confiner/-/blob/main/doc/plugins/gitlab.md
-    args:
-      threshold: 10 # at least 10 passes consecutively with no failures to be a candidate for dequarantine
-      private_token: $QA_GITLAB_CI_TOKEN
-
-      # we do not run quarantined jobs automatically on master, but we still commit to master
-      project_id: gitlab-org/quality/nightly # https://gitlab.com/gitlab-org/quality/nightly/
-      target_project: gitlab-org/gitlab # https://gitlab.com/gitlab-org/gitlab
-      failure_issue_labels: QA,Quality
-      failure_issue_prefix: "Failure in "
-      pwd: qa # E2E specs reside in the qa subdirectory
-      timeout: 30
-      ref: master
-      job_pattern: '.+-quarantine'
-  actions:
-    - dequarantine
diff --git a/qa/.confiner/nightly.yml b/qa/.confiner/nightly.yml
deleted file mode 100644
index 78089525b0e76..0000000000000
--- a/qa/.confiner/nightly.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-- name: Quarantine E2E tests in Nightly that fail consistently
-  plugin:
-    name: gitlab
-    args:
-      threshold: 3
-      private_token: $QA_GITLAB_CI_TOKEN
-      project_id: gitlab-org/quality/nightly # https://gitlab.com/gitlab-org/quality/nightly/
-      target_project: gitlab-org/gitlab
-      failure_issue_labels: QA,Quality,found:nightly
-      failure_issue_prefix: "Failure in "
-      pwd: qa
-      timeout: 30
-      ref: master
-      environment:
-        name: nightly
-        pattern: 'pipeline: :nightly'
-      job_pattern: '^((?!quarantine).)*$'
-  actions:
-    - quarantine
diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb
index cc16d2dfc764d..9df33c4d8d321 100644
--- a/qa/qa/runtime/env.rb
+++ b/qa/qa/runtime/env.rb
@@ -86,6 +86,10 @@ def ci_project_name
         ENV['CI_PROJECT_NAME']
       end
 
+      def schedule_type
+        ENV['SCHEDULE_TYPE']
+      end
+
       def generate_allure_report?
         enabled?(ENV['QA_GENERATE_ALLURE_REPORT'], default: false)
       end
diff --git a/qa/qa/specs/helpers/context_selector.rb b/qa/qa/specs/helpers/context_selector.rb
index ab8e9bc363985..88b3efb84cb6c 100644
--- a/qa/qa/specs/helpers/context_selector.rb
+++ b/qa/qa/specs/helpers/context_selector.rb
@@ -101,7 +101,13 @@ def job_matches?(job_patterns)
         end
 
         def pipeline_from_project_name(project_name)
-          project_name.to_s.start_with?('gitlab-qa') ? Runtime::Env.default_branch : project_name
+          if project_name.to_s.start_with?('gitlab-qa')
+            Runtime::Env.default_branch
+          elsif project_name.to_s == 'gitlab' && Runtime::Env.schedule_type == 'nightly'
+            'nightly'
+          else
+            project_name
+          end
         end
 
         # Get production domain value based on GitLab edition and URI's top level domain
diff --git a/qa/spec/specs/helpers/context_selector_spec.rb b/qa/spec/specs/helpers/context_selector_spec.rb
index f6134cc61776a..3550e78d9e303 100644
--- a/qa/spec/specs/helpers/context_selector_spec.rb
+++ b/qa/spec/specs/helpers/context_selector_spec.rb
@@ -535,6 +535,47 @@
         end
       end
     end
+
+    context 'with CI_PROJECT_NAME set to gitlab and SCHEDULE_TYPE set to nightly' do
+      before do
+        stub_env('CI_PROJECT_NAME', 'gitlab')
+        stub_env('SCHEDULE_TYPE', 'nightly')
+      end
+
+      it 'runs on designated pipeline' do
+        group = describe_successfully do
+          it('runs on nightly', only: { pipeline: :nightly }) {}
+          it('does not run in not_nightly', only: { pipeline: :not_nightly }) {}
+          it('runs on nightly given an array', only: { pipeline: [:canary, :nightly] }) {}
+          it('does not run in not_nightly given an array', only: { pipeline: [:not_nightly, :canary] }) {}
+        end
+
+        aggregate_failures do
+          expect(group.examples[0].execution_result.status).to eq(:passed)
+          expect(group.examples[1].execution_result.status).to eq(:pending)
+          expect(group.examples[2].execution_result.status).to eq(:passed)
+          expect(group.examples[3].execution_result.status).to eq(:pending)
+        end
+      end
+
+      context 'when excluding contexts' do
+        it 'skips designated pipeline' do
+          group = describe_successfully do
+            it('skips nightly', except: { pipeline: :nightly }) {}
+            it('runs in not_nightly', except: { pipeline: :not_nightly }) {}
+            it('skips on nightly given an array', except: { pipeline: [:canary, :nightly] }) {}
+            it('runs in not_nightly given an array', except: { pipeline: [:not_nightly, :canary] }) {}
+          end
+
+          aggregate_failures do
+            expect(group.examples[0].execution_result.status).to eq(:pending)
+            expect(group.examples[1].execution_result.status).to eq(:passed)
+            expect(group.examples[2].execution_result.status).to eq(:pending)
+            expect(group.examples[3].execution_result.status).to eq(:passed)
+          end
+        end
+      end
+    end
   end
 
   context 'with job constraints' do
-- 
GitLab