Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config/entry')
-rw-r--r--lib/gitlab/ci/config/entry/include.rb18
-rw-r--r--lib/gitlab/ci/config/entry/include/rules.rb28
-rw-r--r--lib/gitlab/ci/config/entry/include/rules/rule.rb30
-rw-r--r--lib/gitlab/ci/config/entry/inherit/variables.rb11
-rw-r--r--lib/gitlab/ci/config/entry/job.rb3
-rw-r--r--lib/gitlab/ci/config/entry/processable.rb21
-rw-r--r--lib/gitlab/ci/config/entry/rules.rb2
7 files changed, 78 insertions, 35 deletions
diff --git a/lib/gitlab/ci/config/entry/include.rb b/lib/gitlab/ci/config/entry/include.rb
index ad0ed00aa6f..368d8f07f8d 100644
--- a/lib/gitlab/ci/config/entry/include.rb
+++ b/lib/gitlab/ci/config/entry/include.rb
@@ -9,8 +9,10 @@ module Gitlab
#
class Include < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Configurable
+ include ::Gitlab::Config::Entry::Attributable
- ALLOWED_KEYS = %i[local file remote template artifact job project ref].freeze
+ ALLOWED_KEYS = %i[local file remote template artifact job project ref rules].freeze
validations do
validates :config, hash_or_string: true
@@ -27,6 +29,20 @@ module Gitlab
errors.add(:config, "must specify the file where to fetch the config from")
end
end
+
+ with_options allow_nil: true do
+ validates :rules, array_of_hashes: true
+ end
+ end
+
+ entry :rules, ::Gitlab::Ci::Config::Entry::Include::Rules,
+ description: 'List of evaluable Rules to determine file inclusion.',
+ inherit: false
+
+ attributes :rules
+
+ def skip_config_hash_validation?
+ true
end
end
end
diff --git a/lib/gitlab/ci/config/entry/include/rules.rb b/lib/gitlab/ci/config/entry/include/rules.rb
new file mode 100644
index 00000000000..8eaf9e35aaf
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/include/rules.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ class Include
+ class Rules < ::Gitlab::Config::Entry::ComposableArray
+ include ::Gitlab::Config::Entry::Validatable
+
+ validations do
+ validates :config, presence: true
+ validates :config, type: Array
+ end
+
+ def value
+ @config
+ end
+
+ def composable_class
+ Entry::Include::Rules::Rule
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/include/rules/rule.rb b/lib/gitlab/ci/config/entry/include/rules/rule.rb
new file mode 100644
index 00000000000..d3d0f098814
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/include/rules/rule.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ class Include
+ class Rules::Rule < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Attributable
+
+ ALLOWED_KEYS = %i[if].freeze
+
+ attributes :if
+
+ validations do
+ validates :config, presence: true
+ validates :config, type: { with: Hash }
+ validates :config, allowed_keys: ALLOWED_KEYS
+
+ with_options allow_nil: true do
+ validates :if, expression: true
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/inherit/variables.rb b/lib/gitlab/ci/config/entry/inherit/variables.rb
index aa68833bdb8..adef4d1636a 100644
--- a/lib/gitlab/ci/config/entry/inherit/variables.rb
+++ b/lib/gitlab/ci/config/entry/inherit/variables.rb
@@ -13,9 +13,6 @@ module Gitlab
strategy :ArrayStrategy, if: -> (config) { config.is_a?(Array) }
class BooleanStrategy < ::Gitlab::Config::Entry::Boolean
- def inherit?(_key)
- value
- end
end
class ArrayStrategy < ::Gitlab::Config::Entry::Node
@@ -25,20 +22,12 @@ module Gitlab
validates :config, type: Array
validates :config, array_of_strings: true
end
-
- def inherit?(key)
- value.include?(key.to_s)
- end
end
class UnknownStrategy < ::Gitlab::Config::Entry::Node
def errors
["#{location} should be a bool or array of strings"]
end
-
- def inherit?(key)
- false
- end
end
end
end
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb
index e6d63969161..bd4d5f33689 100644
--- a/lib/gitlab/ci/config/entry/job.rb
+++ b/lib/gitlab/ci/config/entry/job.rb
@@ -16,11 +16,8 @@ module Gitlab
environment coverage retry parallel interruptible timeout
release dast_configuration secrets].freeze
- REQUIRED_BY_NEEDS = %i[stage].freeze
-
validations do
validates :config, allowed_keys: ALLOWED_KEYS + PROCESSABLE_ALLOWED_KEYS
- validates :config, required_keys: REQUIRED_BY_NEEDS, if: :has_needs?
validates :script, presence: true
with_options allow_nil: true do
diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb
index 79dfb0eec1d..3543b5493bd 100644
--- a/lib/gitlab/ci/config/entry/processable.rb
+++ b/lib/gitlab/ci/config/entry/processable.rb
@@ -31,7 +31,7 @@ module Gitlab
with_options allow_nil: true do
validates :extends, array_of_strings_or_string: true
- validates :rules, array_of_hashes: true
+ validates :rules, nested_array_of_hashes: true
validates :resource_group, type: String
end
end
@@ -88,9 +88,6 @@ module Gitlab
validate_against_warnings
end
- # inherit root variables
- @root_variables_value = deps&.variables_value # rubocop:disable Gitlab/ModuleWithInstanceVariables
-
yield if block_given?
end
end
@@ -123,27 +120,13 @@ module Gitlab
stage: stage_value,
extends: extends,
rules: rules_value,
- variables: root_and_job_variables_value, # https://gitlab.com/gitlab-org/gitlab/-/issues/300581
- job_variables: job_variables,
+ job_variables: variables_value.to_h,
root_variables_inheritance: root_variables_inheritance,
only: only_value,
except: except_value,
resource_group: resource_group }.compact
end
- def root_and_job_variables_value
- root_variables = @root_variables_value.to_h # rubocop:disable Gitlab/ModuleWithInstanceVariables
- root_variables = root_variables.select do |key, _|
- inherit_entry&.variables_entry&.inherit?(key)
- end
-
- root_variables.merge(variables_value.to_h)
- end
-
- def job_variables
- variables_value.to_h
- end
-
def root_variables_inheritance
inherit_entry&.variables_entry&.value
end
diff --git a/lib/gitlab/ci/config/entry/rules.rb b/lib/gitlab/ci/config/entry/rules.rb
index bf74f995e80..53e52981471 100644
--- a/lib/gitlab/ci/config/entry/rules.rb
+++ b/lib/gitlab/ci/config/entry/rules.rb
@@ -13,7 +13,7 @@ module Gitlab
end
def value
- @config
+ [@config].flatten
end
def composable_class