2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 12:20:08 -04:00
|
|
|
module Gitlab
|
|
|
|
module Template
|
2016-06-24 15:43:46 -04:00
|
|
|
class GitlabCiYmlTemplate < BaseTemplate
|
2020-10-06 08:08:38 -04:00
|
|
|
BASE_EXCLUDED_PATTERNS = [%r{\.latest\.}].freeze
|
2020-09-08 08:08:41 -04:00
|
|
|
|
2021-06-04 14:10:08 -04:00
|
|
|
TEMPLATES_WITH_LATEST_VERSION = {
|
|
|
|
'Jobs/Browser-Performance-Testing' => true,
|
|
|
|
'Security/API-Fuzzing' => true,
|
|
|
|
'Security/DAST' => true,
|
|
|
|
'Terraform' => true
|
|
|
|
}.freeze
|
|
|
|
|
2020-12-17 16:09:57 -05:00
|
|
|
def description
|
|
|
|
"# This file is a template, and might need editing before it works on your project."
|
2016-06-17 02:37:19 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:20:08 -04:00
|
|
|
class << self
|
2021-06-04 14:10:08 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
2020-09-08 08:08:41 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2016-06-02 12:20:08 -04:00
|
|
|
def extension
|
|
|
|
'.gitlab-ci.yml'
|
|
|
|
end
|
|
|
|
|
|
|
|
def categories
|
|
|
|
{
|
2016-12-21 10:21:55 -05:00
|
|
|
'General' => '',
|
|
|
|
'Pages' => 'Pages',
|
2020-02-18 10:08:51 -05:00
|
|
|
'Verify' => 'Verify',
|
2016-12-23 05:08:09 -05:00
|
|
|
'Auto deploy' => 'autodeploy'
|
2016-06-02 12:20:08 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
def include_categories_for_file
|
|
|
|
{
|
|
|
|
"SAST#{self.extension}" => { 'Security' => 'Security' }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-09-08 08:08:41 -04:00
|
|
|
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-02-18 10:08:51 -05:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:20:08 -04:00
|
|
|
def base_dir
|
2018-09-26 11:39:27 -04:00
|
|
|
Rails.root.join('lib/gitlab/ci/templates')
|
2016-06-02 12:20:08 -04:00
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
def finder(project = nil)
|
2020-02-18 10:08:51 -05:00
|
|
|
Gitlab::Template::Finders::GlobalTemplateFinder.new(
|
2021-01-19 16:10:45 -05:00
|
|
|
self.base_dir,
|
|
|
|
self.extension,
|
|
|
|
self.categories,
|
|
|
|
self.include_categories_for_file,
|
|
|
|
excluded_patterns: self.excluded_patterns
|
2020-02-18 10:08:51 -05:00
|
|
|
)
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2021-06-04 14:10:08 -04:00
|
|
|
|
|
|
|
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-02 12:20:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-07-08 17:09:21 -04:00
|
|
|
Gitlab::Template::GitlabCiYmlTemplate.prepend_mod
|