Commit 7efe65d6 authored by Shinya Maeda's avatar Shinya Maeda

Add latest template for Auto Deploy template

This commit adds the latest template
parent 1948210f
---
title: Hide the latest version of templates from the template selector
merge_request: 40937
author:
type: other
......@@ -16,7 +16,7 @@ All template files reside in the `lib/gitlab/ci/templates` directory, and are ca
| Sub-directory | Content | [Selectable in UI](#make-sure-the-new-template-can-be-selected-in-ui) |
|----------------|--------------------------------------------------------------|-----------------------------------------------------------------------|
| `/AWS/*` | Cloud Deployment (AWS) related jobs | No |
| `/Jobs/*` | Auto DevOps related jobs | Yes |
| `/Jobs/*` | Auto DevOps related jobs | No |
| `/Pages/*` | Static site generators for GitLab Pages (for example Jekyll) | Yes |
| `/Security/*` | Security related jobs | Yes |
| `/Verify/*` | Verify/testing related jobs | Yes |
......
......@@ -14,8 +14,8 @@ module EE
super.merge(categories_ee)
end
override :disabled_templates
def disabled_templates
override :additional_excluded_patterns
def additional_excluded_patterns
[]
end
......
......@@ -5,10 +5,10 @@ module Gitlab
module Template
module Finders
class GlobalTemplateFinder < BaseTemplateFinder
def initialize(base_dir, extension, categories = {}, exclusions: [])
def initialize(base_dir, extension, categories = {}, excluded_patterns: [])
@categories = categories
@extension = extension
@exclusions = exclusions
@excluded_patterns = excluded_patterns
super(base_dir)
end
......@@ -43,7 +43,7 @@ module Gitlab
private
def excluded?(file_name)
@exclusions.include?(file_name)
@excluded_patterns.any? { |pattern| pattern.match?(file_name) }
end
def select_directory(file_name)
......
......@@ -3,12 +3,16 @@
module Gitlab
module Template
class GitlabCiYmlTemplate < BaseTemplate
BASE_EXCLUDED_PATTERNS = [%r{\.latest$}].freeze
def content
explanation = "# This file is a template, and might need editing before it works on your project."
[explanation, super].join("\n")
end
class << self
include Gitlab::Utils::StrongMemoize
def extension
'.gitlab-ci.yml'
end
......@@ -22,10 +26,14 @@ module Gitlab
}
end
def disabled_templates
%w[
Verify/Browser-Performance
]
def excluded_patterns
strong_memoize(:excluded_patterns) do
BASE_EXCLUDED_PATTERNS + additional_excluded_patterns
end
end
def additional_excluded_patterns
[%r{Verify/Browser-Performance}]
end
def base_dir
......@@ -34,7 +42,7 @@ module Gitlab
def finder(project = nil)
Gitlab::Template::Finders::GlobalTemplateFinder.new(
self.base_dir, self.extension, self.categories, exclusions: self.disabled_templates
self.base_dir, self.extension, self.categories, excluded_patterns: self.excluded_patterns
)
end
end
......
......@@ -7,17 +7,17 @@ RSpec.describe 'CI YML Templates' do
let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) }
let(:disabled_templates) do
Gitlab::Template::GitlabCiYmlTemplate.disabled_templates.map do |template|
template + Gitlab::Template::GitlabCiYmlTemplate.extension
let(:excluded_templates) do
all_templates.select do |name|
Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
end
end
context 'included in a CI YAML configuration' do
context 'when including available templates in a CI YAML configuration' do
using RSpec::Parameterized::TableSyntax
where(:template_name) do
all_templates - disabled_templates
all_templates - excluded_templates
end
with_them do
......@@ -41,4 +41,29 @@ RSpec.describe 'CI YML Templates' do
end
end
end
context 'when including unavailable templates in a CI YAML configuration' do
using RSpec::Parameterized::TableSyntax
where(:template_name) do
excluded_templates
end
with_them do
let(:content) do
<<~EOS
include:
- template: #{template_name}
concrete_build_implemented_by_a_user:
stage: test
script: do something
EOS
end
it 'is not valid' do
expect(subject).not_to be_valid
end
end
end
end
......@@ -15,9 +15,9 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do
FileUtils.rm_rf(base_dir)
end
subject(:finder) { described_class.new(base_dir, '', { 'General' => '', 'Bar' => 'Bar' }, exclusions: exclusions) }
subject(:finder) { described_class.new(base_dir, '', { 'General' => '', 'Bar' => 'Bar' }, excluded_patterns: excluded_patterns) }
let(:exclusions) { [] }
let(:excluded_patterns) { [] }
describe '.find' do
context 'with a non-prefixed General template' do
......@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do
end
context 'while listed as an exclusion' do
let(:exclusions) { %w[test-template] }
let(:excluded_patterns) { [%r{^test-template$}] }
it 'does not find the template without a prefix' do
expect(finder.find('test-template')).to be_nil
......@@ -77,7 +77,7 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do
end
context 'while listed as an exclusion' do
let(:exclusions) { %w[Bar/test-template] }
let(:excluded_patterns) { [%r{^Bar/test-template$}] }
it 'does not find the template with a prefix' do
expect(finder.find('Bar/test-template')).to be_nil
......@@ -96,6 +96,17 @@ RSpec.describe Gitlab::Template::Finders::GlobalTemplateFinder do
expect(finder.find('Bar/test-template')).to be_nil
end
end
context 'while listed as an exclusion' do
let(:excluded_patterns) { [%r{\.latest$}] }
it 'excludes the template matched the pattern' do
create_template!('test-template.latest')
expect(finder.find('test-template')).to be_present
expect(finder.find('test-template.latest')).to be_nil
end
end
end
end
end
......@@ -13,6 +13,12 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do
expect(all).to include('Docker')
expect(all).to include('Ruby')
end
it 'does not include Browser-Performance template in FOSS' do
all = subject.all.map(&:name)
expect(all).not_to include('Browser-Performance') unless Gitlab.ee?
end
end
describe '#content' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment