Commit 0c0be8d6 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'cherry-pick-39eb16aa' into 'master'

Pick revert of `require-all-templates-to-include-default-stages'

Closes #59992 and #60106

See merge request gitlab-org/gitlab-ce!27312
parents ffb6995f ef84f7bb
---
title: Require all templates to use default stages
merge_request: 26954
author:
type: fixed
...@@ -73,17 +73,13 @@ module Gitlab ...@@ -73,17 +73,13 @@ module Gitlab
def build_config(config, project:, sha:, user:) def build_config(config, project:, sha:, user:)
initial_config = Gitlab::Config::Loader::Yaml.new(config).load! initial_config = Gitlab::Config::Loader::Yaml.new(config).load!
if project
process_external_files(initial_config, project: project, sha: sha, user: user) process_external_files(initial_config, project: project, sha: sha, user: user)
else
initial_config
end
end end
def process_external_files(config, project:, sha:, user:) def process_external_files(config, project:, sha:, user:)
Config::External::Processor.new(config, Config::External::Processor.new(config,
project: project, project: project,
sha: sha || project.repository.root_ref_sha, sha: sha || project&.repository&.root_ref_sha,
user: user, user: user,
expandset: Set.new).perform expandset: Set.new).perform
end end
......
...@@ -21,7 +21,9 @@ module Gitlab ...@@ -21,7 +21,9 @@ module Gitlab
private private
def validate_content! def validate_content!
if content.nil? if context.project&.repository.nil?
errors.push("Local file `#{location}` does not have project!")
elsif content.nil?
errors.push("Local file `#{location}` does not exist!") errors.push("Local file `#{location}` does not exist!")
elsif content.blank? elsif content.blank?
errors.push("Local file `#{location}` is empty!") errors.push("Local file `#{location}` is empty!")
......
...@@ -6,6 +6,7 @@ stages: ...@@ -6,6 +6,7 @@ stages:
- environment - environment
- build - build
- test - test
- deploy
- internal - internal
- alpha - alpha
- beta - beta
......
...@@ -24,10 +24,6 @@ before_script: ...@@ -24,10 +24,6 @@ before_script:
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail - set -o pipefail
stages:
- build
- test
lintDebug: lintDebug:
stage: build stage: build
script: script:
......
...@@ -60,6 +60,7 @@ variables: ...@@ -60,6 +60,7 @@ variables:
stages: stages:
- build - build
- test - test
- deploy # dummy stage to follow the template guidelines
- review - review
- dast - dast
- staging - staging
......
...@@ -14,9 +14,11 @@ variables: ...@@ -14,9 +14,11 @@ variables:
KITCHEN_LOCAL_YAML: ".kitchen.dokken.yml" KITCHEN_LOCAL_YAML: ".kitchen.dokken.yml"
stages: stages:
- build
- lint - lint
- unit - test
- functional - functional
- deploy
foodcritic: foodcritic:
stage: lint stage: lint
...@@ -29,7 +31,7 @@ cookstyle: ...@@ -29,7 +31,7 @@ cookstyle:
- chef exec cookstyle . - chef exec cookstyle .
chefspec: chefspec:
stage: unit stage: test
script: script:
- chef exec rspec spec - chef exec rspec spec
......
...@@ -18,6 +18,7 @@ before_script: ...@@ -18,6 +18,7 @@ before_script:
stages: stages:
- test - test
- build - build
- deploy
format: format:
stage: test stage: test
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
image: mono:latest image: mono:latest
stages: stages:
- build
- test - test
- deploy - deploy
......
image: ayufan/openshift-cli image: ayufan/openshift-cli
stages: stages:
- build # dummy stage to follow the template guidelines
- test - test
- deploy # dummy stage to follow the template guidelines
- review - review
- staging - staging
- production - production
......
...@@ -9,6 +9,8 @@ before_script: ...@@ -9,6 +9,8 @@ before_script:
stages: stages:
- validate - validate
- build
- test
- deploy - deploy
validate: validate:
......
...@@ -4,6 +4,7 @@ image: alpine:latest ...@@ -4,6 +4,7 @@ image: alpine:latest
stages: stages:
- build - build
- test
- deploy - deploy
.serverless:build:image: .serverless:build:image:
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
# This file assumes an own GitLab CI runner, setup on a macOS system. # This file assumes an own GitLab CI runner, setup on a macOS system.
stages: stages:
- build - build
- test
- archive - archive
- deploy
build_project: build_project:
stage: build stage: build
......
...@@ -24,6 +24,7 @@ before_script: ...@@ -24,6 +24,7 @@ before_script:
stages: stages:
- validate - validate
- build - build
- test
- deploy - deploy
validate: validate:
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
stages: stages:
- build - build
- test
- deploy
variables: variables:
LC_ALL: "en_US.UTF-8" LC_ALL: "en_US.UTF-8"
......
...@@ -16,6 +16,12 @@ module Gitlab ...@@ -16,6 +16,12 @@ module Gitlab
end end
alias_method :key, :name alias_method :key, :name
def full_name
Pathname.new(@path)
.relative_path_from(self.class.base_dir)
.to_s
end
def content def content
@finder.read(@path) @finder.read(@path)
end end
......
...@@ -3,46 +3,32 @@ ...@@ -3,46 +3,32 @@
require 'spec_helper' require 'spec_helper'
describe "CI YML Templates" do describe "CI YML Templates" do
ABSTRACT_TEMPLATES = %w[Serverless].freeze using RSpec::Parameterized::TableSyntax
# 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
def self.concrete_templates
Gitlab::Template::GitlabCiYmlTemplate.all.reject do |template|
ABSTRACT_TEMPLATES.include?(template.name)
end
end
def self.abstract_templates
Gitlab::Template::GitlabCiYmlTemplate.all.select do |template|
ABSTRACT_TEMPLATES.include?(template.name)
end
end
describe 'concrete templates with CI/CD jobs' do subject { Gitlab::Ci::YamlProcessor.new(content) }
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) } where(:template_name) do
.not_to raise_error Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name)
end
end
end end
describe 'abstract templates without concrete jobs defined' do with_them do
abstract_templates.each do |template| let(:content) do
it "#{template.name} template should be valid after being implemented" do <<~EOS
content = template.content + <<~EOS include:
- template: #{template_name}
concrete_build_implemented_by_a_user: concrete_build_implemented_by_a_user:
stage: build stage: test
script: do something script: do something
EOS EOS
end
expect { Gitlab::Ci::YamlProcessor.new(content) }.not_to raise_error it 'is valid' do
expect { subject }.not_to raise_error
end end
it 'require default stages to be included' do
expect(subject.stages).to include(*Gitlab::Ci::Config::Entry::Stages.default)
end end
end end
end end
...@@ -615,19 +615,19 @@ module Gitlab ...@@ -615,19 +615,19 @@ module Gitlab
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config), opts) } subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config), opts) }
context "when validating a ci config file with no project context" do context "when validating a ci config file with no project context" do
context "when a single string is provided", :quarantine do context "when a single string is provided" do
let(:include_content) { "/local.gitlab-ci.yml" } let(:include_content) { "/local.gitlab-ci.yml" }
it "does not return any error" do it "returns a validation error" do
expect { subject }.not_to raise_error expect { subject }.to raise_error /does not have project/
end end
end end
context "when an array is provided" do context "when an array is provided" do
let(:include_content) { ["/local.gitlab-ci.yml"] } let(:include_content) { ["/local.gitlab-ci.yml"] }
it "does not return any error" do it "returns a validation error" do
expect { subject }.not_to raise_error expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /does not have project/)
end end
end end
...@@ -643,11 +643,18 @@ module Gitlab ...@@ -643,11 +643,18 @@ module Gitlab
let(:include_content) do let(:include_content) do
[ [
'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml', 'https://gitlab.com/awesome-project/raw/master/.before-script-template.yml',
'/templates/.after-script-template.yml',
{ template: 'Auto-DevOps.gitlab-ci.yml' } { template: 'Auto-DevOps.gitlab-ci.yml' }
] ]
end 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 it "does not return any error" do
expect { subject }.not_to raise_error expect { subject }.not_to raise_error
end end
......
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