From 6d49ccca8f6e042294040113b42bbfd153b5f87f Mon Sep 17 00:00:00 2001 From: lma-git Date: Tue, 21 Feb 2023 12:54:32 -0800 Subject: [PATCH 1/3] Expose whether pipeline config injects an keyword Added a new method to ProjectConfig sources to indicate whether the content is modified with an extra 'include' keyword. Then this information is passed along into the External processor context --- ee/lib/gitlab/ci/project_config/compliance.rb | 4 +++ .../ci/pipeline/chain/config/content_spec.rb | 3 ++- lib/gitlab/ci/config.rb | 9 ++++--- lib/gitlab/ci/config/external/context.rb | 10 ++++++-- lib/gitlab/ci/pipeline/chain/command.rb | 3 ++- .../ci/pipeline/chain/config/content.rb | 1 + .../ci/pipeline/chain/config/process.rb | 1 + lib/gitlab/ci/project_config.rb | 1 + lib/gitlab/ci/project_config/auto_devops.rb | 4 +++ .../ci/project_config/external_project.rb | 4 +++ lib/gitlab/ci/project_config/remote.rb | 4 +++ lib/gitlab/ci/project_config/repository.rb | 4 +++ lib/gitlab/ci/project_config/source.rb | 5 ++++ .../gitlab/ci/config/external/context_spec.rb | 25 +++++++++++++++++++ .../ci/pipeline/chain/config/content_spec.rb | 11 +++++++- .../ci/project_config/repository_spec.rb | 8 +++++- .../gitlab/ci/project_config/source_spec.rb | 8 +++++- 17 files changed, 95 insertions(+), 10 deletions(-) diff --git a/ee/lib/gitlab/ci/project_config/compliance.rb b/ee/lib/gitlab/ci/project_config/compliance.rb index 4f1881a35d3c7b..127e85f4c08375 100644 --- a/ee/lib/gitlab/ci/project_config/compliance.rb +++ b/ee/lib/gitlab/ci/project_config/compliance.rb @@ -16,6 +16,10 @@ def content end end + def internal_include_injected? + true + end + def source :compliance_source end diff --git a/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb index 778ae68f996e0c..1c84cc8f002088 100644 --- a/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb +++ b/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Config::Content do +RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Config::Content, feature_category: :continuous_integration do let(:ci_config_path) { nil } let(:pipeline) { build(:ci_pipeline, project: project) } let(:content) { nil } @@ -36,6 +36,7 @@ expect(pipeline.config_source).to eq 'compliance_source' expect(pipeline.pipeline_config.content).to eq(content_result) expect(command.config_content).to eq(content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 585e671ce426be..f6c4e94a064463 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -21,14 +21,15 @@ class Config attr_reader :root, :context, :source_ref_path, :source, :logger - def initialize(config, project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, source: nil, logger: nil) + # rubocop: disable Metrics/ParameterLists + def initialize(config, project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, source: nil, pipeline_config: nil, logger: nil) @logger = logger || ::Gitlab::Ci::Pipeline::Logger.new(project: project) @source_ref_path = pipeline&.source_ref_path @project = project @context = self.logger.instrument(:config_build_context, once: true) do pipeline ||= ::Ci::Pipeline.new(project: project, sha: sha, user: user, source: source) - build_context(project: project, pipeline: pipeline, sha: sha, user: user, parent_pipeline: parent_pipeline) + build_context(project: project, pipeline: pipeline, sha: sha, user: user, parent_pipeline: parent_pipeline, pipeline_config: pipeline_config) end @context.set_deadline(TIMEOUT_SECONDS) @@ -49,6 +50,7 @@ def initialize(config, project: nil, pipeline: nil, sha: nil, user: nil, parent_ rescue *rescue_errors => e raise Config::ConfigError, e.message end + # rubocop: enable Metrics/ParameterLists def valid? @root.valid? @@ -157,13 +159,14 @@ def find_sha(project) end end - def build_context(project:, pipeline:, sha:, user:, parent_pipeline:) + def build_context(project:, pipeline:, sha:, user:, parent_pipeline:, pipeline_config:) Config::External::Context.new( project: project, sha: sha || find_sha(project), user: user, parent_pipeline: parent_pipeline, variables: build_variables(pipeline: pipeline), + pipeline_config: pipeline_config, logger: logger) end diff --git a/lib/gitlab/ci/config/external/context.rb b/lib/gitlab/ci/config/external/context.rb index 6eef279d3de843..805b76496685a6 100644 --- a/lib/gitlab/ci/config/external/context.rb +++ b/lib/gitlab/ci/config/external/context.rb @@ -14,20 +14,21 @@ class Context include ::Gitlab::Utils::StrongMemoize - attr_reader :project, :sha, :user, :parent_pipeline, :variables + attr_reader :project, :sha, :user, :parent_pipeline, :variables, :pipeline_config attr_reader :expandset, :execution_deadline, :logger, :max_includes delegate :instrument, to: :logger def initialize( project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, - logger: nil + pipeline_config: nil, logger: nil ) @project = project @sha = sha @user = user @parent_pipeline = parent_pipeline @variables = variables || Ci::Variables::Collection.new + @pipeline_config = pipeline_config @expandset = Feature.enabled?(:ci_includes_count_duplicates, project) ? [] : Set.new @execution_deadline = 0 @logger = logger || Gitlab::Ci::Pipeline::Logger.new(project: project) @@ -91,6 +92,11 @@ def includes expandset.map(&:metadata) end + # Indicates if an 'include' was internally injected into the config content + def internal_include_injected? + !!pipeline_config&.internal_include_injected? + end + protected attr_writer :expandset, :execution_deadline, :logger, :max_includes diff --git a/lib/gitlab/ci/pipeline/chain/command.rb b/lib/gitlab/ci/pipeline/chain/command.rb index d2dc712e366a6b..4bc2f6c7be70cb 100644 --- a/lib/gitlab/ci/pipeline/chain/command.rb +++ b/lib/gitlab/ci/pipeline/chain/command.rb @@ -13,7 +13,8 @@ module Chain :seeds_block, :variables_attributes, :push_options, :chat_data, :allow_mirror_update, :bridge, :content, :dry_run, :logger, # These attributes are set by Chains during processing: - :config_content, :yaml_processor_result, :workflow_rules_result, :pipeline_seed + :config_content, :yaml_processor_result, :workflow_rules_result, :pipeline_seed, + :pipeline_config ) do include Gitlab::Utils::StrongMemoize diff --git a/lib/gitlab/ci/pipeline/chain/config/content.rb b/lib/gitlab/ci/pipeline/chain/config/content.rb index d41213ef6dde3e..779aac7d5209eb 100644 --- a/lib/gitlab/ci/pipeline/chain/config/content.rb +++ b/lib/gitlab/ci/pipeline/chain/config/content.rb @@ -14,6 +14,7 @@ def perform! @pipeline.build_pipeline_config(content: pipeline_config.content) @command.config_content = pipeline_config.content @pipeline.config_source = pipeline_config.source + @command.pipeline_config = pipeline_config else error('Missing CI config file') end diff --git a/lib/gitlab/ci/pipeline/chain/config/process.rb b/lib/gitlab/ci/pipeline/chain/config/process.rb index ad6b2fd341172f..4976e075727b3e 100644 --- a/lib/gitlab/ci/pipeline/chain/config/process.rb +++ b/lib/gitlab/ci/pipeline/chain/config/process.rb @@ -20,6 +20,7 @@ def perform! source: @pipeline.source, user: current_user, parent_pipeline: parent_pipeline, + pipeline_config: @command.pipeline_config, logger: logger } ) diff --git a/lib/gitlab/ci/project_config.rb b/lib/gitlab/ci/project_config.rb index ded6877ef2915b..0563b16c5e1ce8 100644 --- a/lib/gitlab/ci/project_config.rb +++ b/lib/gitlab/ci/project_config.rb @@ -26,6 +26,7 @@ def initialize(project:, sha:, custom_content: nil, pipeline_source: nil, pipeli end delegate :content, :source, to: :@config, allow_nil: true + delegate :internal_include_injected?, to: :@config def exists? !!@config&.exists? diff --git a/lib/gitlab/ci/project_config/auto_devops.rb b/lib/gitlab/ci/project_config/auto_devops.rb index c6905f480a2a61..dcb3a57ca6980b 100644 --- a/lib/gitlab/ci/project_config/auto_devops.rb +++ b/lib/gitlab/ci/project_config/auto_devops.rb @@ -13,6 +13,10 @@ def content end end + def internal_include_injected? + true + end + def source :auto_devops_source end diff --git a/lib/gitlab/ci/project_config/external_project.rb b/lib/gitlab/ci/project_config/external_project.rb index 0ed5d6fa2268b8..cdd59f3a833854 100644 --- a/lib/gitlab/ci/project_config/external_project.rb +++ b/lib/gitlab/ci/project_config/external_project.rb @@ -17,6 +17,10 @@ def content end end + def internal_include_injected? + true + end + def source :external_project_source end diff --git a/lib/gitlab/ci/project_config/remote.rb b/lib/gitlab/ci/project_config/remote.rb index cf1292706d2372..24004f48f85da4 100644 --- a/lib/gitlab/ci/project_config/remote.rb +++ b/lib/gitlab/ci/project_config/remote.rb @@ -12,6 +12,10 @@ def content end end + def internal_include_injected? + true + end + def source :remote_source end diff --git a/lib/gitlab/ci/project_config/repository.rb b/lib/gitlab/ci/project_config/repository.rb index 435ad4d42fe6c4..089f8a74ae97b2 100644 --- a/lib/gitlab/ci/project_config/repository.rb +++ b/lib/gitlab/ci/project_config/repository.rb @@ -12,6 +12,10 @@ def content end end + def internal_include_injected? + true + end + def source :repository_source end diff --git a/lib/gitlab/ci/project_config/source.rb b/lib/gitlab/ci/project_config/source.rb index ebe5728163b007..2e8c030e0e6194 100644 --- a/lib/gitlab/ci/project_config/source.rb +++ b/lib/gitlab/ci/project_config/source.rb @@ -24,6 +24,11 @@ def content raise NotImplementedError end + # Indicates if we are internally injecting an 'include' into the content + def internal_include_injected? + false + end + def source raise NotImplementedError end diff --git a/spec/lib/gitlab/ci/config/external/context_spec.rb b/spec/lib/gitlab/ci/config/external/context_spec.rb index ee28137e54f283..57c8c5ac9d30f0 100644 --- a/spec/lib/gitlab/ci/config/external/context_spec.rb +++ b/spec/lib/gitlab/ci/config/external/context_spec.rb @@ -170,4 +170,29 @@ describe '#sentry_payload' do it { expect(subject.sentry_payload).to match(a_hash_including(:project, :user)) } end + + describe '#internal_include_injected?' do + context 'when pipeline_config is provided' do + let(:pipeline_config) { instance_double(Gitlab::Ci::ProjectConfig) } + let(:attributes) do + { project: project, user: user, sha: sha, variables: variables, pipeline_config: pipeline_config } + end + + where(:value) { [true, false] } + + with_them do + it 'returns the value of .internal_include_injected?' do + allow(pipeline_config).to receive(:internal_include_injected?).and_return(value) + + expect(subject.internal_include_injected?).to eq(value) + end + end + end + + context 'when pipeline_config is not provided' do + it 'returns false' do + expect(subject.internal_include_injected?).to eq(false) + end + end + end end diff --git a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb index e0d656f456eddb..8d258693b70cda 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content do +RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content, feature_category: :continuous_integration do let(:project) { create(:project, ci_config_path: ci_config_path) } let(:pipeline) { build(:ci_pipeline, project: project) } let(:content) { nil } @@ -26,6 +26,7 @@ expect(pipeline.config_source).to eq 'bridge_source' expect(command.config_content).to eq 'the-yaml' + expect(command.pipeline_config.internal_include_injected?).to eq(false) end end @@ -52,6 +53,7 @@ expect(pipeline.config_source).to eq 'repository_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end @@ -71,6 +73,7 @@ expect(pipeline.config_source).to eq 'remote_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end @@ -91,6 +94,7 @@ expect(pipeline.config_source).to eq 'external_project_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end context 'when path specifies a refname' do @@ -111,6 +115,7 @@ expect(pipeline.config_source).to eq 'external_project_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end end @@ -138,6 +143,7 @@ expect(pipeline.config_source).to eq 'repository_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end @@ -161,6 +167,7 @@ expect(pipeline.config_source).to eq 'auto_devops_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) + expect(command.pipeline_config.internal_include_injected?).to eq(true) end end @@ -181,6 +188,7 @@ expect(pipeline.config_source).to eq 'parameter_source' expect(pipeline.pipeline_config.content).to eq(content) expect(command.config_content).to eq(content) + expect(command.pipeline_config.internal_include_injected?).to eq(false) end end @@ -197,6 +205,7 @@ expect(pipeline.config_source).to eq('unknown_source') expect(pipeline.pipeline_config).to be_nil expect(command.config_content).to be_nil + expect(command.pipeline_config).to be_nil expect(pipeline.errors.full_messages).to include('Missing CI config file') end end diff --git a/spec/lib/gitlab/ci/project_config/repository_spec.rb b/spec/lib/gitlab/ci/project_config/repository_spec.rb index 2105b691d9ee35..a30a7b1fd27948 100644 --- a/spec/lib/gitlab/ci/project_config/repository_spec.rb +++ b/spec/lib/gitlab/ci/project_config/repository_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::ProjectConfig::Repository do +RSpec.describe Gitlab::Ci::ProjectConfig::Repository, feature_category: :continuous_integration do let(:project) { create(:project, :custom_repo, files: files) } let(:sha) { project.repository.head_commit.sha } let(:files) { { 'README.md' => 'hello' } } @@ -44,4 +44,10 @@ it { is_expected.to eq(:repository_source) } end + + describe '#internal_include_injected?' do + subject { config.internal_include_injected? } + + it { is_expected.to eq(true) } + end end diff --git a/spec/lib/gitlab/ci/project_config/source_spec.rb b/spec/lib/gitlab/ci/project_config/source_spec.rb index dda5c7cdce8312..ad55233f53208c 100644 --- a/spec/lib/gitlab/ci/project_config/source_spec.rb +++ b/spec/lib/gitlab/ci/project_config/source_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Ci::ProjectConfig::Source do +RSpec.describe Gitlab::Ci::ProjectConfig::Source, feature_category: :continuous_integration do let_it_be(:custom_config_class) { Class.new(described_class) } let_it_be(:project) { build_stubbed(:project) } let_it_be(:sha) { '123456' } @@ -20,4 +20,10 @@ it { expect { source }.to raise_error(NotImplementedError) } end + + describe '#internal_include_injected?' do + subject(:internal_include_injected) { custom_config.internal_include_injected? } + + it { expect(internal_include_injected).to eq(false) } + end end -- GitLab From 214fb845569b729d70bd4c56af84cf7f9c6f9c37 Mon Sep 17 00:00:00 2001 From: lma-git Date: Wed, 22 Feb 2023 08:55:13 -0800 Subject: [PATCH 2/3] Update term to contains_internal_include --- ee/lib/gitlab/ci/project_config/compliance.rb | 2 +- .../ci/pipeline/chain/config/content_spec.rb | 2 +- lib/gitlab/ci/config/external/context.rb | 5 ++--- lib/gitlab/ci/project_config.rb | 2 +- lib/gitlab/ci/project_config/auto_devops.rb | 2 +- lib/gitlab/ci/project_config/external_project.rb | 2 +- lib/gitlab/ci/project_config/remote.rb | 2 +- lib/gitlab/ci/project_config/repository.rb | 2 +- lib/gitlab/ci/project_config/source.rb | 2 +- .../gitlab/ci/config/external/context_spec.rb | 10 +++++----- .../ci/pipeline/chain/config/content_spec.rb | 16 ++++++++-------- .../gitlab/ci/project_config/repository_spec.rb | 4 ++-- spec/lib/gitlab/ci/project_config/source_spec.rb | 6 +++--- 13 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ee/lib/gitlab/ci/project_config/compliance.rb b/ee/lib/gitlab/ci/project_config/compliance.rb index 127e85f4c08375..ad0594724f14a9 100644 --- a/ee/lib/gitlab/ci/project_config/compliance.rb +++ b/ee/lib/gitlab/ci/project_config/compliance.rb @@ -16,7 +16,7 @@ def content end end - def internal_include_injected? + def contains_internal_include? true end diff --git a/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb index 1c84cc8f002088..558dc6a8b5caf6 100644 --- a/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb +++ b/ee/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -36,7 +36,7 @@ expect(pipeline.config_source).to eq 'compliance_source' expect(pipeline.pipeline_config.content).to eq(content_result) expect(command.config_content).to eq(content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end diff --git a/lib/gitlab/ci/config/external/context.rb b/lib/gitlab/ci/config/external/context.rb index 805b76496685a6..44ce5e8302d880 100644 --- a/lib/gitlab/ci/config/external/context.rb +++ b/lib/gitlab/ci/config/external/context.rb @@ -92,9 +92,8 @@ def includes expandset.map(&:metadata) end - # Indicates if an 'include' was internally injected into the config content - def internal_include_injected? - !!pipeline_config&.internal_include_injected? + def contains_internal_include? + !!pipeline_config&.contains_internal_include? end protected diff --git a/lib/gitlab/ci/project_config.rb b/lib/gitlab/ci/project_config.rb index 0563b16c5e1ce8..e69efb85a937f6 100644 --- a/lib/gitlab/ci/project_config.rb +++ b/lib/gitlab/ci/project_config.rb @@ -26,7 +26,7 @@ def initialize(project:, sha:, custom_content: nil, pipeline_source: nil, pipeli end delegate :content, :source, to: :@config, allow_nil: true - delegate :internal_include_injected?, to: :@config + delegate :contains_internal_include?, to: :@config def exists? !!@config&.exists? diff --git a/lib/gitlab/ci/project_config/auto_devops.rb b/lib/gitlab/ci/project_config/auto_devops.rb index dcb3a57ca6980b..70f8c7b9bb3f23 100644 --- a/lib/gitlab/ci/project_config/auto_devops.rb +++ b/lib/gitlab/ci/project_config/auto_devops.rb @@ -13,7 +13,7 @@ def content end end - def internal_include_injected? + def contains_internal_include? true end diff --git a/lib/gitlab/ci/project_config/external_project.rb b/lib/gitlab/ci/project_config/external_project.rb index cdd59f3a833854..b29825514585cb 100644 --- a/lib/gitlab/ci/project_config/external_project.rb +++ b/lib/gitlab/ci/project_config/external_project.rb @@ -17,7 +17,7 @@ def content end end - def internal_include_injected? + def contains_internal_include? true end diff --git a/lib/gitlab/ci/project_config/remote.rb b/lib/gitlab/ci/project_config/remote.rb index 24004f48f85da4..17d5a9ee68fd96 100644 --- a/lib/gitlab/ci/project_config/remote.rb +++ b/lib/gitlab/ci/project_config/remote.rb @@ -12,7 +12,7 @@ def content end end - def internal_include_injected? + def contains_internal_include? true end diff --git a/lib/gitlab/ci/project_config/repository.rb b/lib/gitlab/ci/project_config/repository.rb index 089f8a74ae97b2..c975023d35e27a 100644 --- a/lib/gitlab/ci/project_config/repository.rb +++ b/lib/gitlab/ci/project_config/repository.rb @@ -12,7 +12,7 @@ def content end end - def internal_include_injected? + def contains_internal_include? true end diff --git a/lib/gitlab/ci/project_config/source.rb b/lib/gitlab/ci/project_config/source.rb index 2e8c030e0e6194..30edf1b552a5bb 100644 --- a/lib/gitlab/ci/project_config/source.rb +++ b/lib/gitlab/ci/project_config/source.rb @@ -25,7 +25,7 @@ def content end # Indicates if we are internally injecting an 'include' into the content - def internal_include_injected? + def contains_internal_include? false end diff --git a/spec/lib/gitlab/ci/config/external/context_spec.rb b/spec/lib/gitlab/ci/config/external/context_spec.rb index 57c8c5ac9d30f0..bae898e13ebdfb 100644 --- a/spec/lib/gitlab/ci/config/external/context_spec.rb +++ b/spec/lib/gitlab/ci/config/external/context_spec.rb @@ -171,7 +171,7 @@ it { expect(subject.sentry_payload).to match(a_hash_including(:project, :user)) } end - describe '#internal_include_injected?' do + describe '#contains_internal_include?' do context 'when pipeline_config is provided' do let(:pipeline_config) { instance_double(Gitlab::Ci::ProjectConfig) } let(:attributes) do @@ -181,17 +181,17 @@ where(:value) { [true, false] } with_them do - it 'returns the value of .internal_include_injected?' do - allow(pipeline_config).to receive(:internal_include_injected?).and_return(value) + it 'returns the value of .contains_internal_include?' do + allow(pipeline_config).to receive(:contains_internal_include?).and_return(value) - expect(subject.internal_include_injected?).to eq(value) + expect(subject.contains_internal_include?).to eq(value) end end end context 'when pipeline_config is not provided' do it 'returns false' do - expect(subject.internal_include_injected?).to eq(false) + expect(subject.contains_internal_include?).to eq(false) end end end diff --git a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb index 8d258693b70cda..434acfb52742e1 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -26,7 +26,7 @@ expect(pipeline.config_source).to eq 'bridge_source' expect(command.config_content).to eq 'the-yaml' - expect(command.pipeline_config.internal_include_injected?).to eq(false) + expect(command.pipeline_config.contains_internal_include?).to eq(false) end end @@ -53,7 +53,7 @@ expect(pipeline.config_source).to eq 'repository_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end @@ -73,7 +73,7 @@ expect(pipeline.config_source).to eq 'remote_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end @@ -94,7 +94,7 @@ expect(pipeline.config_source).to eq 'external_project_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end context 'when path specifies a refname' do @@ -115,7 +115,7 @@ expect(pipeline.config_source).to eq 'external_project_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end end @@ -143,7 +143,7 @@ expect(pipeline.config_source).to eq 'repository_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end @@ -167,7 +167,7 @@ expect(pipeline.config_source).to eq 'auto_devops_source' expect(pipeline.pipeline_config.content).to eq(config_content_result) expect(command.config_content).to eq(config_content_result) - expect(command.pipeline_config.internal_include_injected?).to eq(true) + expect(command.pipeline_config.contains_internal_include?).to eq(true) end end @@ -188,7 +188,7 @@ expect(pipeline.config_source).to eq 'parameter_source' expect(pipeline.pipeline_config.content).to eq(content) expect(command.config_content).to eq(content) - expect(command.pipeline_config.internal_include_injected?).to eq(false) + expect(command.pipeline_config.contains_internal_include?).to eq(false) end end diff --git a/spec/lib/gitlab/ci/project_config/repository_spec.rb b/spec/lib/gitlab/ci/project_config/repository_spec.rb index a30a7b1fd27948..b31a909934879b 100644 --- a/spec/lib/gitlab/ci/project_config/repository_spec.rb +++ b/spec/lib/gitlab/ci/project_config/repository_spec.rb @@ -45,8 +45,8 @@ it { is_expected.to eq(:repository_source) } end - describe '#internal_include_injected?' do - subject { config.internal_include_injected? } + describe '#contains_internal_include?' do + subject { config.contains_internal_include? } it { is_expected.to eq(true) } end diff --git a/spec/lib/gitlab/ci/project_config/source_spec.rb b/spec/lib/gitlab/ci/project_config/source_spec.rb index ad55233f53208c..5248cf080e8df0 100644 --- a/spec/lib/gitlab/ci/project_config/source_spec.rb +++ b/spec/lib/gitlab/ci/project_config/source_spec.rb @@ -21,9 +21,9 @@ it { expect { source }.to raise_error(NotImplementedError) } end - describe '#internal_include_injected?' do - subject(:internal_include_injected) { custom_config.internal_include_injected? } + describe '#contains_internal_include?' do + subject(:contains_internal_include) { custom_config.contains_internal_include? } - it { expect(internal_include_injected).to eq(false) } + it { expect(contains_internal_include).to eq(false) } end end -- GitLab From ec6da9dcc9c211ed8cbfb7cca3f883f9723a3e28 Mon Sep 17 00:00:00 2001 From: lma-git Date: Thu, 23 Feb 2023 09:35:19 -0800 Subject: [PATCH 3/3] Add clarifying comment on internal include --- lib/gitlab/ci/config/external/context.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/gitlab/ci/config/external/context.rb b/lib/gitlab/ci/config/external/context.rb index 44ce5e8302d880..ab0477e4d44f00 100644 --- a/lib/gitlab/ci/config/external/context.rb +++ b/lib/gitlab/ci/config/external/context.rb @@ -92,6 +92,8 @@ def includes expandset.map(&:metadata) end + # Some ProjectConfig sources inject an `include` into the config content. We use this + # method to exclude that `include` from the calculation of the total included files. def contains_internal_include? !!pipeline_config&.contains_internal_include? end -- GitLab