Commit c269619f authored by Albert Salim's avatar Albert Salim

Add Danger to validate pipeline changes

Use Danger to provide guidance to consider
effects of pipeline changes and the need
to communicate broadly
parent f3bde212
# frozen_string_literal: true
MESSAGE = <<~MESSAGE
## Pipeline Changes
This Merge Request contains changes to the pipeline configuration for the GitLab project.
Please consider the effect of the changes in this Merge Request on the following:
- Effects on different [pipeline types](https://docs.gitlab.com/ee/development/pipelines.html#pipelines-for-merge-requests)
- Effects on non-canonical projects (`gitlab-foss`, `security`, etc)
- Effects on [pipeline performance](https://about.gitlab.com/handbook/engineering/quality/performance-indicators/#average-merge-request-pipeline-duration-for-gitlab)
- Effects on fork pipelines
Please consider communicating these changes to the broader team following the [communication guideline for pipeline changes](https://about.gitlab.com/handbook/engineering/quality/engineering-productivity-team/#pipeline-changes)
MESSAGE
if helper.has_ci_changes?
markdown(MESSAGE)
end
...@@ -268,6 +268,10 @@ module Gitlab ...@@ -268,6 +268,10 @@ module Gitlab
def has_database_scoped_labels?(current_mr_labels) def has_database_scoped_labels?(current_mr_labels)
current_mr_labels.any? { |label| label.start_with?('database::') } current_mr_labels.any? { |label| label.start_with?('database::') }
end end
def has_ci_changes?
changed_files(%r{\A(\.gitlab-ci\.yml|\.gitlab/ci/)}).any?
end
end end
end end
end end
...@@ -14,6 +14,7 @@ class GitlabDanger ...@@ -14,6 +14,7 @@ class GitlabDanger
product_analytics product_analytics
utility_css utility_css
pajamas pajamas
pipeline
].freeze ].freeze
CI_ONLY_RULES ||= %w[ CI_ONLY_RULES ||= %w[
......
...@@ -591,4 +591,30 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -591,4 +591,30 @@ RSpec.describe Gitlab::Danger::Helper do
expect(helper.prepare_labels_for_mr([])).to eq('') expect(helper.prepare_labels_for_mr([])).to eq('')
end end
end end
describe '#has_ci_changes?' do
context 'when .gitlab/ci is changed' do
it 'returns true' do
expect(helper).to receive(:all_changed_files).and_return(%w[migration.rb .gitlab/ci/test.yml])
expect(helper.has_ci_changes?).to be_truthy
end
end
context 'when .gitlab-ci.yml is changed' do
it 'returns true' do
expect(helper).to receive(:all_changed_files).and_return(%w[migration.rb .gitlab-ci.yml])
expect(helper.has_ci_changes?).to be_truthy
end
end
context 'when neither .gitlab/ci/ or .gitlab-ci.yml is changed' do
it 'returns false' do
expect(helper).to receive(:all_changed_files).and_return(%w[migration.rb nested/.gitlab-ci.yml])
expect(helper.has_ci_changes?).to be_falsey
end
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'fast_spec_helper'
RSpec.describe GitlabDanger do RSpec.describe GitlabDanger do
let(:gitlab_danger_helper) { nil } let(:gitlab_danger_helper) { nil }
...@@ -9,7 +9,7 @@ RSpec.describe GitlabDanger do ...@@ -9,7 +9,7 @@ RSpec.describe GitlabDanger do
describe '.local_warning_message' do describe '.local_warning_message' do
it 'returns an informational message with rules that can run' 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: changes_size, documentation, frozen_string, duplicate_yarn_dependencies, prettier, eslint, karma, database, commit_messages, product_analytics, utility_css, pajamas') expect(described_class.local_warning_message).to eq("==> Only the following Danger rules can be run locally: #{described_class::LOCAL_RULES.join(', ')}")
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment