debian-mirror-gitlab/lib/gitlab/template/gitlab_ci_yml_template.rb

93 lines
2.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-06-22 15:30:34 +05:30
module Gitlab
module Template
2016-09-13 17:45:13 +05:30
class GitlabCiYmlTemplate < BaseTemplate
2021-01-03 14:25:43 +05:30
BASE_EXCLUDED_PATTERNS = [%r{\.latest\.}].freeze
2020-11-24 15:15:51 +05:30
2021-09-04 01:27:46 +05:30
TEMPLATES_WITH_LATEST_VERSION = {
2021-11-18 22:05:49 +05:30
'Jobs/Build' => true
2021-09-04 01:27:46 +05:30
}.freeze
2021-03-08 18:12:59 +05:30
def description
"# This file is a template, and might need editing before it works on your project."
2016-06-22 15:30:34 +05:30
end
class << self
2021-09-04 01:27:46 +05:30
extend ::Gitlab::Utils::Override
2020-11-24 15:15:51 +05:30
include Gitlab::Utils::StrongMemoize
2016-06-22 15:30:34 +05:30
def extension
'.gitlab-ci.yml'
end
def categories
{
2017-08-17 22:00:37 +05:30
'General' => '',
'Pages' => 'Pages',
2020-04-08 14:13:33 +05:30
'Verify' => 'Verify',
2017-08-17 22:00:37 +05:30
'Auto deploy' => 'autodeploy'
2016-06-22 15:30:34 +05:30
}
end
2021-03-11 19:13:27 +05:30
def include_categories_for_file
{
"SAST#{self.extension}" => { 'Security' => 'Security' }
}
end
2020-11-24 15:15:51 +05:30
def excluded_patterns
strong_memoize(:excluded_patterns) do
BASE_EXCLUDED_PATTERNS + additional_excluded_patterns
end
end
def additional_excluded_patterns
[%r{Verify/Browser-Performance}]
2020-04-08 14:13:33 +05:30
end
2016-06-22 15:30:34 +05:30
def base_dir
2018-12-05 23:21:45 +05:30
Rails.root.join('lib/gitlab/ci/templates')
2016-06-22 15:30:34 +05:30
end
2016-09-13 17:45:13 +05:30
def finder(project = nil)
2020-04-08 14:13:33 +05:30
Gitlab::Template::Finders::GlobalTemplateFinder.new(
2021-03-11 19:13:27 +05:30
self.base_dir,
self.extension,
self.categories,
self.include_categories_for_file,
excluded_patterns: self.excluded_patterns
2020-04-08 14:13:33 +05:30
)
2016-09-13 17:45:13 +05:30
end
2021-09-04 01:27:46 +05:30
override :find
def find(key, project = nil)
if try_redirect_to_latest?(key, project)
key += '.latest'
end
super(key, project)
end
private
# To gauge the impact of the latest template,
# you can redirect the stable template to the latest template by enabling the feature flag.
# See https://docs.gitlab.com/ee/development/cicd/templates.html#versioning for more information.
def try_redirect_to_latest?(key, project)
return false unless templates_with_latest_version[key]
flag_name = "redirect_to_latest_template_#{key.underscore.tr('/', '_')}"
::Feature.enabled?(flag_name, project, default_enabled: :yaml)
end
def templates_with_latest_version
TEMPLATES_WITH_LATEST_VERSION
end
2016-06-22 15:30:34 +05:30
end
end
end
end
2019-12-04 20:38:33 +05:30
2021-09-30 23:02:18 +05:30
Gitlab::Template::GitlabCiYmlTemplate.prepend_mod