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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.5 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
2021-06-08 01:23:25 +05:30
class Cache < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Configurable
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
2023-07-09 08:55:56 +05:30
ALLOWED_KEYS = %i[key untracked paths when policy unprotect fallback_keys].freeze
2021-06-08 01:23:25 +05:30
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'
2023-07-09 08:55:56 +05:30
DEFAULT_FALLBACK_KEYS = [].freeze
2021-06-08 01:23:25 +05:30
validations do
validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
2023-03-04 22:38:38 +05:30
validates :policy, type: String, allow_blank: true, inclusion: {
in: ALLOWED_POLICY,
message: "should be one of: #{ALLOWED_POLICY.join(', ')}"
}
2021-06-08 01:23:25 +05:30
with_options allow_nil: true do
2023-03-04 22:38:38 +05:30
validates :when, type: String, inclusion: {
in: ALLOWED_WHEN,
message: "should be one of: #{ALLOWED_WHEN.join(', ')}"
}
2023-07-09 08:55:56 +05:30
validates :fallback_keys, length: { maximum: 5, too_long: "has to many entries (maximum %{count})" }
2021-01-03 14:25:43 +05:30
end
2016-09-13 17:45:13 +05:30
end
2021-06-08 01:23:25 +05:30
entry :key, Entry::Key,
description: 'Cache key used to define a cache affinity.'
2021-04-17 20:07:23 +05:30
2023-03-17 16:20:25 +05:30
entry :unprotect, ::Gitlab::Config::Entry::Boolean,
description: 'Unprotect the cache from a protected ref.'
2021-06-08 01:23:25 +05:30
entry :untracked, ::Gitlab::Config::Entry::Boolean,
description: 'Cache all untracked files.'
2016-08-24 12:49:21 +05:30
2021-06-08 01:23:25 +05:30
entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.'
2016-08-24 12:49:21 +05:30
2023-07-09 08:55:56 +05:30
entry :fallback_keys, ::Gitlab::Config::Entry::ArrayOfStrings,
description: 'List of keys to download cache from if no cache hit occurred for key'
attributes :policy, :when, :unprotect, :fallback_keys
2017-08-17 22:00:37 +05:30
2021-06-08 01:23:25 +05:30
def value
result = super
2017-09-10 17:25:29 +05:30
2021-06-08 01:23:25 +05:30
result[:key] = key_value
2023-03-17 16:20:25 +05:30
result[:unprotect] = unprotect || false
2021-06-08 01:23:25 +05:30
result[:policy] = policy || DEFAULT_POLICY
# Use self.when to avoid conflict with reserved word
result[:when] = self.when || DEFAULT_WHEN
2023-07-09 08:55:56 +05:30
result[:fallback_keys] = fallback_keys || DEFAULT_FALLBACK_KEYS
2017-09-10 17:25:29 +05:30
2021-06-08 01:23:25 +05:30
result
2021-04-17 20:07:23 +05:30
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