From 004862d69d104eebcbcb15ca667babce184039d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Coutable?= <remy@rymai.me>
Date: Tue, 24 Jan 2023 19:18:50 +0100
Subject: [PATCH] ci: Dry up main .gitlab-ci.yml file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rémy Coutable <remy@rymai.me>
---
 .gitlab-ci.yml | 49 +++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 595a41fd8ca05..4e604e6d3f6e0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,6 +24,18 @@ default:
   # Default job timeout set to 90m https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/10520
   timeout: 90m
 
+.ruby3-variables: &ruby3-variables
+  RUBY_VERSION: "3.0"
+  OMNIBUS_GITLAB_RUBY3_BUILD: "true"
+  OMNIBUS_GITLAB_CACHE_EDITION: "GITLAB_RUBY3"
+
+.ruby2-variables: &ruby2-variables
+  RUBY_VERSION: "2.7"
+
+.default-branch-incident-variables: &default-branch-incident-variables
+  CREATE_INCIDENT_FOR_PIPELINE_FAILURE: "true"
+  NOTIFY_PIPELINE_FAILURE_CHANNEL: "master-broken"
+
 workflow:
   name: '$PIPELINE_NAME'
   rules:
@@ -41,67 +53,56 @@ workflow:
     # For merge requests running exclusively in Ruby 2.7
     - if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-in-ruby2/'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
         PIPELINE_NAME: 'Ruby 2 $CI_MERGE_REQUEST_EVENT_TYPE MR pipeline'
     # For (detached) merge request pipelines.
     - if: '$CI_MERGE_REQUEST_IID'
       variables:
-        RUBY_VERSION: "3.0"
-        OMNIBUS_GITLAB_RUBY3_BUILD: "true"
-        OMNIBUS_GITLAB_CACHE_EDITION: "GITLAB_RUBY3"
+        <<: *ruby3-variables
         PIPELINE_NAME: 'Ruby 3 $CI_MERGE_REQUEST_EVENT_TYPE MR pipeline'
     # For the scheduled pipelines, we set specific variables.
     - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "schedule"'
       variables:
-        RUBY_VERSION: "3.0"
-        OMNIBUS_GITLAB_RUBY3_BUILD: "true"
-        OMNIBUS_GITLAB_CACHE_EDITION: "GITLAB_RUBY3"
+        <<: *ruby3-variables
+        <<: *default-branch-incident-variables
         CRYSTALBALL: "true"
-        CREATE_INCIDENT_FOR_PIPELINE_FAILURE: "true"
-        NOTIFY_PIPELINE_FAILURE_CHANNEL: "master-broken"
         PIPELINE_NAME: 'Scheduled $CI_COMMIT_BRANCH pipeline'
     # Run pipelines for ruby2 branch
     - if: '$CI_COMMIT_BRANCH == "ruby2" && $CI_PIPELINE_SOURCE == "schedule"'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
         NOTIFY_PIPELINE_FAILURE_CHANNEL: "f_ruby3"
         PIPELINE_NAME: 'Scheduled ruby 2 pipeline'
     # This work around https://gitlab.com/gitlab-org/gitlab/-/issues/332411 whichs prevents usage of dependency proxy
     # when pipeline is triggered by a project access token.
     - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GITLAB_USER_LOGIN =~ /project_\d+_bot\d*/'
       variables:
-        RUBY_VERSION: "3.0"
-        OMNIBUS_GITLAB_RUBY3_BUILD: "true"
-        OMNIBUS_GITLAB_CACHE_EDITION: "GITLAB_RUBY3"
+        <<: *ruby3-variables
+        <<: *default-branch-incident-variables
         GITLAB_DEPENDENCY_PROXY_ADDRESS: ""
-        CREATE_INCIDENT_FOR_PIPELINE_FAILURE: "true"
-        NOTIFY_PIPELINE_FAILURE_CHANNEL: "master-broken"
     # For `$CI_DEFAULT_BRANCH` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
     - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
       variables:
-        RUBY_VERSION: "3.0"
-        OMNIBUS_GITLAB_RUBY3_BUILD: "true"
-        OMNIBUS_GITLAB_CACHE_EDITION: "GITLAB_RUBY3"
-        CREATE_INCIDENT_FOR_PIPELINE_FAILURE: "true"
-        NOTIFY_PIPELINE_FAILURE_CHANNEL: "master-broken"
+        <<: *ruby3-variables
+        <<: *default-branch-incident-variables
     # For tags, create a pipeline.
     - if: '$CI_COMMIT_TAG'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
     # If `$GITLAB_INTERNAL` isn't set, don't create a pipeline.
     - if: '$GITLAB_INTERNAL == null'
       when: never
     # For stable, auto-deploy, and security branches, create a pipeline.
     - if: '$CI_COMMIT_BRANCH =~ /^[\d-]+-stable(-ee)?$/'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
         NOTIFY_PIPELINE_FAILURE_CHANNEL: "releases"
     - if: '$CI_COMMIT_BRANCH =~ /^\d+-\d+-auto-deploy-\d+$/'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
     - if: '$CI_COMMIT_BRANCH =~ /^security\//'
       variables:
-        RUBY_VERSION: "2.7"
+        <<: *ruby2-variables
 
 variables:
   PG_VERSION: "12"
-- 
GitLab