debian-mirror-gitlab/lib/gitlab/ci/config/entry/cache.rb

98 lines
3.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-08-24 12:49:21 +05:30
##
# Entry that represents a cache configuration
#
2021-04-17 20:07:23 +05:30
class Cache < ::Gitlab::Config::Entry::Simplifiable
2021-04-29 21:17:54 +05:30
strategy :Caches, if: -> (config) { Feature.enabled?(:multiple_cache_per_job, default_enabled: :yaml) }
strategy :Cache, if: -> (config) { Feature.disabled?(:multiple_cache_per_job, default_enabled: :yaml) }
2021-04-17 20:07:23 +05:30
class Caches < ::Gitlab::Config::Entry::ComposableArray
include ::Gitlab::Config::Entry::Validatable
MULTIPLE_CACHE_LIMIT = 4
validations do
validate do
unless config.is_a?(Hash) || config.is_a?(Array)
errors.add(:config, 'can only be a Hash or an Array')
end
if config.is_a?(Array) && config.count > MULTIPLE_CACHE_LIMIT
errors.add(:config, "no more than #{MULTIPLE_CACHE_LIMIT} caches can be created")
end
end
end
def initialize(*args)
super
@key = nil
end
def composable_class
Entry::Cache::Cache
2021-01-03 14:25:43 +05:30
end
2016-09-13 17:45:13 +05:30
end
2021-04-17 20:07:23 +05:30
class Cache < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Configurable
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
ALLOWED_KEYS = %i[key untracked paths when policy].freeze
ALLOWED_POLICY = %w[pull-push push pull].freeze
DEFAULT_POLICY = 'pull-push'
ALLOWED_WHEN = %w[on_success on_failure always].freeze
DEFAULT_WHEN = 'on_success'
validations do
validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
validates :policy,
inclusion: { in: ALLOWED_POLICY, message: 'should be pull-push, push, or pull' },
allow_blank: true
with_options allow_nil: true do
validates :when,
inclusion: {
in: ALLOWED_WHEN,
message: 'should be on_success, on_failure or always'
}
end
end
2016-08-24 12:49:21 +05:30
2021-04-17 20:07:23 +05:30
entry :key, Entry::Key,
description: 'Cache key used to define a cache affinity.'
2016-08-24 12:49:21 +05:30
2021-04-17 20:07:23 +05:30
entry :untracked, ::Gitlab::Config::Entry::Boolean,
description: 'Cache all untracked files.'
2017-08-17 22:00:37 +05:30
2021-04-17 20:07:23 +05:30
entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.'
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
attributes :policy, :when
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
def value
result = super
result[:key] = key_value
result[:policy] = policy || DEFAULT_POLICY
# Use self.when to avoid conflict with reserved word
result[:when] = self.when || DEFAULT_WHEN
result
end
end
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
class UnknownStrategy < ::Gitlab::Config::Entry::Node
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
end
end
end
end
end