From f06b84ef9a689a8c4cc83d30e5f89ddb2e216477 Mon Sep 17 00:00:00 2001
From: Alessio Caiazza <376774-nolith@users.noreply.gitlab.com>
Date: Fri, 2 Jul 2021 12:01:13 +0200
Subject: [PATCH] Add gitaly gem bump danger check

---
 danger/gitaly/Dangerfile                   | 22 ++++++++++++++++++++++
 spec/tooling/danger/project_helper_spec.rb |  2 +-
 tooling/danger/project_helper.rb           |  1 +
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 danger/gitaly/Dangerfile

diff --git a/danger/gitaly/Dangerfile b/danger/gitaly/Dangerfile
new file mode 100644
index 000000000000..59e55845c83d
--- /dev/null
+++ b/danger/gitaly/Dangerfile
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+TEMPLATE_MESSAGE = <<~MSG
+This merge request requires coordination with gitaly deployments.
+Before merging this merge request we should verify that gitaly
+running in production already implements the new gRPC interface
+included here.
+
+Failing to do so will introduce a [non backward compatible
+change](https://docs.gitlab.com/ee/development/multi_version_compatibility.html)
+during canary depoyment that can cause an incident.
+
+1. Identify the gitaly MR introducing the new interface
+1. Verify that the environment widget contains a `gprd` deployment
+MSG
+
+changed_lines = helper.changed_lines('Gemfile.lock')
+if changed_lines.any? { |line| line =~ /^\+\s+gitaly \(/ }
+  warn 'Changing gitaly gem can cause a multi-version incompatibility incident'
+
+  markdown(TEMPLATE_MESSAGE)
+end
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb
index d2d706fad3f1..9c4e9407f907 100644
--- a/spec/tooling/danger/project_helper_spec.rb
+++ b/spec/tooling/danger/project_helper_spec.rb
@@ -221,7 +221,7 @@
 
   describe '.local_warning_message' do
     it 'returns an informational message with rules that can run' do
-      expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, database, datateam, documentation, duplicate_yarn_dependencies, eslint, karma, pajamas, pipeline, prettier, product_intelligence, utility_css')
+      expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, database, datateam, documentation, duplicate_yarn_dependencies, eslint, gitaly, karma, pajamas, pipeline, prettier, product_intelligence, utility_css')
     end
   end
 
diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb
index 5e2970169f6c..45a53ac29229 100644
--- a/tooling/danger/project_helper.rb
+++ b/tooling/danger/project_helper.rb
@@ -10,6 +10,7 @@ module ProjectHelper
         documentation
         duplicate_yarn_dependencies
         eslint
+        gitaly
         karma
         pajamas
         pipeline
-- 
GitLab