Revert "Merge branch 'require-all-templates-to-include-default-stages' into 'master'"

This reverts merge request !26954
This commit is contained in:
Sean McGivern 2019-04-05 13:18:35 +00:00
parent 4dd53240fb
commit e32c82ed1e
18 changed files with 49 additions and 63 deletions

View file

@ -1,5 +0,0 @@
---
title: Require all templates to use default stages
merge_request: 26954
author:
type: fixed

View file

@ -73,13 +73,17 @@ module Gitlab
def build_config(config, project:, sha:, user:)
initial_config = Gitlab::Config::Loader::Yaml.new(config).load!
process_external_files(initial_config, project: project, sha: sha, user: user)
if project
process_external_files(initial_config, project: project, sha: sha, user: user)
else
initial_config
end
end
def process_external_files(config, project:, sha:, user:)
Config::External::Processor.new(config,
project: project,
sha: sha || project&.repository&.root_ref_sha,
sha: sha || project.repository.root_ref_sha,
user: user,
expandset: Set.new).perform
end

View file

@ -21,9 +21,7 @@ module Gitlab
private
def validate_content!
if context.project&.repository.nil?
errors.push("Local file `#{location}` does not have project!")
elsif content.nil?
if content.nil?
errors.push("Local file `#{location}` does not exist!")
elsif content.blank?
errors.push("Local file `#{location}` is empty!")

View file

@ -6,7 +6,6 @@ stages:
- environment
- build
- test
- deploy
- internal
- alpha
- beta

View file

@ -24,6 +24,10 @@ before_script:
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
lintDebug:
stage: build
script:

View file

@ -60,7 +60,6 @@ variables:
stages:
- build
- test
- deploy # dummy stage to follow the template guidelines
- review
- dast
- staging

View file

@ -14,11 +14,9 @@ variables:
KITCHEN_LOCAL_YAML: ".kitchen.dokken.yml"
stages:
- build
- lint
- test
- unit
- functional
- deploy
foodcritic:
stage: lint
@ -31,7 +29,7 @@ cookstyle:
- chef exec cookstyle .
chefspec:
stage: test
stage: unit
script:
- chef exec rspec spec

View file

@ -18,7 +18,6 @@ before_script:
stages:
- test
- build
- deploy
format:
stage: test

View file

@ -15,7 +15,6 @@
image: mono:latest
stages:
- build
- test
- deploy

View file

@ -1,9 +1,7 @@
image: ayufan/openshift-cli
stages:
- build # dummy stage to follow the template guidelines
- test
- deploy # dummy stage to follow the template guidelines
- review
- staging
- production

View file

@ -9,8 +9,6 @@ before_script:
stages:
- validate
- build
- test
- deploy
validate:

View file

@ -4,7 +4,6 @@ image: alpine:latest
stages:
- build
- test
- deploy
.serverless:build:image:

View file

@ -2,9 +2,7 @@
# This file assumes an own GitLab CI runner, setup on a macOS system.
stages:
- build
- test
- archive
- deploy
build_project:
stage: build

View file

@ -24,7 +24,6 @@ before_script:
stages:
- validate
- build
- test
- deploy
validate:

View file

@ -12,8 +12,6 @@
stages:
- build
- test
- deploy
variables:
LC_ALL: "en_US.UTF-8"

View file

@ -16,12 +16,6 @@ module Gitlab
end
alias_method :key, :name
def full_name
Pathname.new(@path)
.relative_path_from(self.class.base_dir)
.to_s
end
def content
@finder.read(@path)
end

View file

@ -3,32 +3,46 @@
require 'spec_helper'
describe "CI YML Templates" do
using RSpec::Parameterized::TableSyntax
ABSTRACT_TEMPLATES = %w[Serverless].freeze
# These templates depend on the presence of the `project`
# param to enable processing of `include:` within CI config.
PROJECT_DEPENDENT_TEMPLATES = %w[Auto-DevOps DAST].freeze
subject { Gitlab::Ci::YamlProcessor.new(content) }
where(:template_name) do
Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name)
def self.concrete_templates
Gitlab::Template::GitlabCiYmlTemplate.all.reject do |template|
ABSTRACT_TEMPLATES.include?(template.name)
end
end
with_them do
let(:content) do
<<~EOS
include:
- template: #{template_name}
concrete_build_implemented_by_a_user:
stage: test
script: do something
EOS
def self.abstract_templates
Gitlab::Template::GitlabCiYmlTemplate.all.select do |template|
ABSTRACT_TEMPLATES.include?(template.name)
end
end
it 'is valid' do
expect { subject }.not_to raise_error
describe 'concrete templates with CI/CD jobs' do
concrete_templates.each do |template|
it "#{template.name} template should be valid" do
# Trigger processing of included files
project = create(:project, :test_repo) if PROJECT_DEPENDENT_TEMPLATES.include?(template.name)
expect { Gitlab::Ci::YamlProcessor.new(template.content, project: project) }
.not_to raise_error
end
end
end
it 'require default stages to be included' do
expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
describe 'abstract templates without concrete jobs defined' do
abstract_templates.each do |template|
it "#{template.name} template should be valid after being implemented" do
content = template.content + <<~EOS
concrete_build_implemented_by_a_user:
stage: build
script: do something
EOS
expect { Gitlab::Ci::YamlProcessor.new(content) }.not_to raise_error
end
end
end
end

View file

@ -626,8 +626,8 @@ module Gitlab
context "when an array is provided" do
let(:include_content) { ["/local.gitlab-ci.yml"] }
it "returns a validation error" do
expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /does not have project/)
it "does not return any error" do
expect { subject }.not_to raise_error
end
end
@ -643,18 +643,11 @@ module Gitlab
let(:include_content) do
[
'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml',
'/templates/.after-script-template.yml',
{ template: 'Auto-DevOps.gitlab-ci.yml' }
]
end
before do
WebMock.stub_request(:get, 'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml')
.to_return(
status: 200,
headers: { 'Content-Type' => 'application/json' },
body: 'prepare: { script: ls -al }')
end
it "does not return any error" do
expect { subject }.not_to raise_error
end