diff options
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r-- | lib/gitlab/ci/config/entry/bridge.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/default.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/include/rules.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/include/rules/rule.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/processable.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/context.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/file/component.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/mapper/verifier.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/external/rules.rb | 44 | ||||
-rw-r--r-- | lib/gitlab/ci/config/interpolation/interpolator.rb | 7 |
11 files changed, 55 insertions, 60 deletions
diff --git a/lib/gitlab/ci/config/entry/bridge.rb b/lib/gitlab/ci/config/entry/bridge.rb index ee99354cb28..1119afab24a 100644 --- a/lib/gitlab/ci/config/entry/bridge.rb +++ b/lib/gitlab/ci/config/entry/bridge.rb @@ -51,7 +51,7 @@ module Gitlab entry :parallel, Entry::Product::Parallel, description: 'Parallel configuration for this job.', inherit: false, - metadata: { allowed_strategies: %i(matrix) } + metadata: { allowed_strategies: %i[matrix] } attributes :when, :allow_failure, :parallel diff --git a/lib/gitlab/ci/config/entry/default.rb b/lib/gitlab/ci/config/entry/default.rb index e996b6b1312..476b928e471 100644 --- a/lib/gitlab/ci/config/entry/default.rb +++ b/lib/gitlab/ci/config/entry/default.rb @@ -14,7 +14,7 @@ module Gitlab include ::Gitlab::Config::Entry::Inheritable ALLOWED_KEYS = %i[before_script after_script hooks cache image services - interruptible timeout retry tags artifacts].freeze + interruptible timeout retry tags artifacts id_tokens].freeze validations do validates :config, allowed_keys: ALLOWED_KEYS @@ -65,6 +65,11 @@ module Gitlab description: 'Default artifacts.', inherit: false + entry :id_tokens, ::Gitlab::Config::Entry::ComposableHash, + description: 'Configured JWTs for this job', + inherit: false, + metadata: { composable_class: ::Gitlab::Ci::Config::Entry::IdToken } + private def overwrite_entry(deps, key, current_entry) diff --git a/lib/gitlab/ci/config/entry/include/rules.rb b/lib/gitlab/ci/config/entry/include/rules.rb index 71418e6752d..a3799b36ece 100644 --- a/lib/gitlab/ci/config/entry/include/rules.rb +++ b/lib/gitlab/ci/config/entry/include/rules.rb @@ -19,11 +19,6 @@ module Gitlab validates :config, type: Array end - # Remove this method when FF `ci_refactor_external_rules` is removed - def value - Feature.enabled?(:ci_refactor_external_rules) ? super : @config - end - def composable_class Entry::Include::Rules::Rule end diff --git a/lib/gitlab/ci/config/entry/include/rules/rule.rb b/lib/gitlab/ci/config/entry/include/rules/rule.rb index 1a68e95913c..df8509eecc0 100644 --- a/lib/gitlab/ci/config/entry/include/rules/rule.rb +++ b/lib/gitlab/ci/config/entry/include/rules/rule.rb @@ -7,13 +7,17 @@ module Gitlab class Include class Rules::Rule < ::Gitlab::Config::Entry::Node include ::Gitlab::Config::Entry::Validatable + include ::Gitlab::Config::Entry::Configurable include ::Gitlab::Config::Entry::Attributable - ALLOWED_KEYS = %i[if exists when].freeze + ALLOWED_KEYS = %i[if exists when changes].freeze ALLOWED_WHEN = %w[never always].freeze attributes :if, :exists, :when + entry :changes, Entry::Rules::Rule::Changes, + description: 'File change condition rule.' + validations do validates :config, presence: true validates :config, type: { with: Hash } @@ -27,7 +31,9 @@ module Gitlab end def value - Feature.enabled?(:ci_refactor_external_rules) ? config.compact : super + config.merge( + changes: (changes_value if changes_defined?) + ).compact end end end diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index d31d1b366c3..c40d665f320 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -13,7 +13,7 @@ module Gitlab ALLOWED_WHEN = %w[on_success on_failure always manual delayed].freeze ALLOWED_KEYS = %i[tags script image services start_in artifacts cache dependencies before_script after_script hooks - environment coverage retry parallel interruptible timeout + coverage retry parallel interruptible timeout release id_tokens publish].freeze validations do @@ -102,10 +102,6 @@ module Gitlab metadata: { allowed_needs: %i[job cross_dependency] }, inherit: false - entry :environment, Entry::Environment, - description: 'Environment configuration for this job.', - inherit: false - entry :coverage, Entry::Coverage, description: 'Coverage configuration for this job.', inherit: false @@ -124,7 +120,7 @@ module Gitlab entry :id_tokens, ::Gitlab::Config::Entry::ComposableHash, description: 'Configured JWTs for this job', - inherit: false, + inherit: true, metadata: { composable_class: ::Gitlab::Ci::Config::Entry::IdToken } entry :publish, Entry::Publish, @@ -160,13 +156,11 @@ module Gitlab when: self.when, start_in: self.start_in, dependencies: dependencies, - environment: environment_defined? ? environment_value : nil, - environment_name: environment_defined? ? environment_value[:name] : nil, coverage: coverage_defined? ? coverage_value : nil, retry: retry_defined? ? retry_value : nil, parallel: has_parallel? ? parallel_value : nil, interruptible: interruptible_defined? ? interruptible_value : nil, - timeout: has_timeout? ? ChronicDuration.parse(timeout.to_s) : nil, + timeout: parsed_timeout, artifacts: artifacts_value, release: release_value, after_script: after_script_value, @@ -180,6 +174,12 @@ module Gitlab ).compact end + def parsed_timeout + return unless has_timeout? + + ChronicDuration.parse(timeout.to_s, use_complete_matcher: true) + end + def ignored? allow_failure_defined? ? static_allow_failure : manual_action? end diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index e0f0903174c..88734ac1186 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -15,7 +15,7 @@ module Gitlab include ::Gitlab::Config::Entry::Inheritable PROCESSABLE_ALLOWED_KEYS = %i[extends stage only except rules variables - inherit allow_failure when needs resource_group].freeze + inherit allow_failure when needs resource_group environment].freeze MAX_NESTING_LEVEL = 10 included do @@ -68,6 +68,10 @@ module Gitlab inherit: false, default: {} + entry :environment, Entry::Environment, + description: 'Environment configuration for this job.', + inherit: false + attributes :extends, :rules, :resource_group end @@ -125,6 +129,8 @@ module Gitlab root_variables_inheritance: root_variables_inheritance, only: only_value, except: except_value, + environment: environment_defined? ? environment_value : nil, + environment_name: environment_defined? ? environment_value[:name] : nil, resource_group: resource_group }.compact end diff --git a/lib/gitlab/ci/config/external/context.rb b/lib/gitlab/ci/config/external/context.rb index c57391d355c..0a524fdba66 100644 --- a/lib/gitlab/ci/config/external/context.rb +++ b/lib/gitlab/ci/config/external/context.rb @@ -9,22 +9,21 @@ module Gitlab TimeoutError = Class.new(StandardError) - TEMP_MAX_INCLUDES = 100 # For logging; to be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/396776 - include ::Gitlab::Utils::StrongMemoize attr_reader :project, :sha, :user, :parent_pipeline, :variables, :pipeline_config - attr_reader :expandset, :execution_deadline, :logger, :max_includes, :max_total_yaml_size_bytes + attr_reader :pipeline, :expandset, :execution_deadline, :logger, :max_includes, :max_total_yaml_size_bytes attr_accessor :total_file_size_in_bytes delegate :instrument, to: :logger def initialize( - project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, + project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, pipeline_config: nil, logger: nil ) @project = project + @pipeline = pipeline @sha = sha @user = user @parent_pipeline = parent_pipeline @@ -60,6 +59,7 @@ module Gitlab def mutate(attrs = {}) self.class.new(**attrs) do |ctx| + ctx.pipeline = pipeline ctx.expandset = expandset ctx.execution_deadline = execution_deadline ctx.logger = logger @@ -106,7 +106,7 @@ module Gitlab protected - attr_writer :expandset, :execution_deadline, :logger, :max_includes, :max_total_yaml_size_bytes + attr_writer :pipeline, :expandset, :execution_deadline, :logger, :max_includes, :max_total_yaml_size_bytes private diff --git a/lib/gitlab/ci/config/external/file/component.rb b/lib/gitlab/ci/config/external/file/component.rb index 15cc0783b86..de6de1bb7a8 100644 --- a/lib/gitlab/ci/config/external/file/component.rb +++ b/lib/gitlab/ci/config/external/file/component.rb @@ -18,6 +18,8 @@ module Gitlab def content return unless component_result.success? + ::Gitlab::UsageDataCounters::HLLRedisCounter.track_event('cicd_component_usage', values: context.user.id) + component_result.payload.fetch(:content) end strong_memoize_attr :content diff --git a/lib/gitlab/ci/config/external/mapper/verifier.rb b/lib/gitlab/ci/config/external/mapper/verifier.rb index 580cae8a207..0e296aa0b5b 100644 --- a/lib/gitlab/ci/config/external/mapper/verifier.rb +++ b/lib/gitlab/ci/config/external/mapper/verifier.rb @@ -40,7 +40,7 @@ module Gitlab file.validate_content! if file.valid? file.load_and_validate_expanded_hash! if file.valid? - next unless Feature.enabled?(:introduce_ci_max_total_yaml_size_bytes, context.project) && file.valid? + next unless file.valid? # We are checking the file.content.to_s because that is returning the actual content of the file, # whereas file.content would return the BatchLoader. diff --git a/lib/gitlab/ci/config/external/rules.rb b/lib/gitlab/ci/config/external/rules.rb index 0e6209460e0..05266fbff0c 100644 --- a/lib/gitlab/ci/config/external/rules.rb +++ b/lib/gitlab/ci/config/external/rules.rb @@ -5,29 +5,19 @@ module Gitlab class Config module External class Rules - # Remove these two constants when FF `ci_refactor_external_rules` is removed - ALLOWED_KEYS = Entry::Include::Rules::Rule::ALLOWED_KEYS - ALLOWED_WHEN = Entry::Include::Rules::Rule::ALLOWED_WHEN - InvalidIncludeRulesError = Class.new(Mapper::Error) def initialize(rule_hashes) - if Feature.enabled?(:ci_refactor_external_rules) - return unless rule_hashes - - # We must compose the include rules entry here because included - # files are expanded before `@root.compose!` runs in Ci::Config. - rules_entry = Entry::Include::Rules.new(rule_hashes) - rules_entry.compose! + return unless rule_hashes - raise InvalidIncludeRulesError, "include:#{rules_entry.errors.first}" unless rules_entry.valid? + # We must compose the include rules entry here because included + # files are expanded before `@root.compose!` runs in Ci::Config. + rules_entry = Entry::Include::Rules.new(rule_hashes) + rules_entry.compose! - @rule_list = Build::Rules::Rule.fabricate_list(rules_entry.value) - else - validate(rule_hashes) + raise InvalidIncludeRulesError, "include:#{rules_entry.errors.first}" unless rules_entry.valid? - @rule_list = Build::Rules::Rule.fabricate_list(rule_hashes) - end + @rule_list = Build::Rules::Rule.fabricate_list(rules_entry.value) end def evaluate(context) @@ -38,28 +28,14 @@ module Gitlab else Result.new('never') end + rescue Build::Rules::Rule::Clause::ParseError => e + raise InvalidIncludeRulesError, "include:#{e.message}" end private def match_rule(context) - @rule_list.find { |rule| rule.matches?(nil, context) } - end - - # Remove this method when FF `ci_refactor_external_rules` is removed - def validate(rule_hashes) - return unless rule_hashes.is_a?(Array) - - rule_hashes.each do |rule_hash| - next if (rule_hash.keys - ALLOWED_KEYS).empty? && valid_when?(rule_hash) - - raise InvalidIncludeRulesError, "invalid include rule: #{rule_hash}" - end - end - - # Remove this method when FF `ci_refactor_external_rules` is removed - def valid_when?(rule_hash) - rule_hash[:when].nil? || rule_hash[:when].in?(ALLOWED_WHEN) + @rule_list.find { |rule| rule.matches?(context.pipeline, context) } end Result = Struct.new(:when) do diff --git a/lib/gitlab/ci/config/interpolation/interpolator.rb b/lib/gitlab/ci/config/interpolation/interpolator.rb index 58965890184..95c419d7427 100644 --- a/lib/gitlab/ci/config/interpolation/interpolator.rb +++ b/lib/gitlab/ci/config/interpolation/interpolator.rb @@ -37,7 +37,12 @@ module Gitlab def interpolate! return @errors.push(config.error) unless config.valid? - return @errors.push('unknown input arguments') if inputs_without_header? + + if inputs_without_header? + return @errors.push( + _('Given inputs not defined in the `spec` section of the included configuration file')) + end + return @result ||= config.content unless config.has_header? return @errors.concat(header.errors) unless header.valid? |