diff --git a/config/feature_flags/development/ci_value_change_for_processable_and_rules_entry.yml b/config/feature_flags/development/ci_value_change_for_processable_and_rules_entry.yml new file mode 100644 index 0000000000000000000000000000000000000000..f7c2542cb22f8baf8a231b151bd68b855d3266b7 --- /dev/null +++ b/config/feature_flags/development/ci_value_change_for_processable_and_rules_entry.yml @@ -0,0 +1,8 @@ +--- +name: ci_value_change_for_processable_and_rules_entry +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/90238 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/365876 +milestone: '15.2' +type: development +group: group::pipeline authoring +default_enabled: false diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index 46afedbcc3ad725e6d7ca98c4046bd0709f89052..d17c52a3ace6ea427005e14c8e871c1873b57d67 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -71,9 +71,9 @@ module Processable end def compose!(deps = nil) - super do - has_workflow_rules = deps&.workflow_entry&.has_rules? + has_workflow_rules = deps&.workflow_entry&.has_rules? + super do # If workflow:rules: or rules: are used # they are considered not compatible # with `only/except` defaults @@ -86,12 +86,16 @@ def compose!(deps = nil) @entries.delete(:except) unless except_defined? # rubocop:disable Gitlab/ModuleWithInstanceVariables end - unless has_workflow_rules - validate_against_warnings + unless ::Feature.enabled?(:ci_value_change_for_processable_and_rules_entry) + validate_against_warnings unless has_workflow_rules end yield if block_given? end + + if ::Feature.enabled?(:ci_value_change_for_processable_and_rules_entry) + validate_against_warnings unless has_workflow_rules + end end def validate_against_warnings diff --git a/lib/gitlab/ci/config/entry/rules.rb b/lib/gitlab/ci/config/entry/rules.rb index 53e529814717185ecc5e3e1a019a39fbd8596615..4f2f08889a16ae0dfbed0afd50964128df33dc19 100644 --- a/lib/gitlab/ci/config/entry/rules.rb +++ b/lib/gitlab/ci/config/entry/rules.rb @@ -13,7 +13,12 @@ class Rules < ::Gitlab::Config::Entry::ComposableArray end def value - [@config].flatten + if ::Feature.enabled?(:ci_value_change_for_processable_and_rules_entry) + # `flatten` is needed to make it work with nested `!reference` + [super].flatten + else + [@config].flatten + end end def composable_class diff --git a/spec/lib/gitlab/ci/config/entry/processable_spec.rb b/spec/lib/gitlab/ci/config/entry/processable_spec.rb index 5b9337ede3437a09f151ee211051f9151e50c4b0..cc32c57e873f4313d088b1fde93393155f3a9244 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -278,8 +278,13 @@ def self.name context 'when workflow rules is not used' do let(:workflow) { double('workflow', 'has_rules?' => false) } + let(:ci_value_change_for_processable_and_rules_entry) { true } before do + stub_feature_flags( + ci_value_change_for_processable_and_rules_entry: ci_value_change_for_processable_and_rules_entry + ) + entry.compose!(deps) end @@ -303,6 +308,14 @@ def self.name it 'raises a warning' do expect(entry.warnings).to contain_exactly(/may allow multiple pipelines/) end + + context 'when the FF ci_value_change_for_processable_and_rules_entry is disabled' do + let(:ci_value_change_for_processable_and_rules_entry) { false } + + it 'raises a warning' do + expect(entry.warnings).to contain_exactly(/may allow multiple pipelines/) + end + end end context 'and its value is `never`' do diff --git a/spec/lib/gitlab/ci/config/entry/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/rules_spec.rb index cfec33003e4e6f220232252a9cdb84b26a8f018e..faae5aa121f12219833d51d6af83f2e79911ca99 100644 --- a/spec/lib/gitlab/ci/config/entry/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/rules_spec.rb @@ -1,10 +1,13 @@ # frozen_string_literal: true require 'fast_spec_helper' +require 'support/helpers/stubbed_feature' require 'support/helpers/stub_feature_flags' require_dependency 'active_model' RSpec.describe Gitlab::Ci::Config::Entry::Rules do + include StubFeatureFlags + let(:factory) do Gitlab::Config::Entry::Factory.new(described_class) .metadata(metadata) @@ -12,13 +15,12 @@ end let(:metadata) { { allowed_when: %w[always never] } } - let(:entry) { factory.create! } - describe '.new' do - subject { entry } + subject(:entry) { factory.create! } + describe '.new' do before do - subject.compose! + entry.compose! end context 'with a list of rule rule' do @@ -73,7 +75,11 @@ end describe '#value' do - subject { entry.value } + subject(:value) { entry.value } + + before do + entry.compose! + end context 'with a list of rule rule' do let(:config) do @@ -99,7 +105,15 @@ { if: '$SKIP', when: 'never' } end - it { is_expected.to eq([config]) } + it { is_expected.to eq([]) } + + context 'when the FF ci_value_change_for_processable_and_rules_entry is disabled' do + before do + stub_feature_flags(ci_value_change_for_processable_and_rules_entry: false) + end + + it { is_expected.to eq([config]) } + end end context 'with nested rules' do