Commit 4bb60b07 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify CI config and remove logical validation

parent 41bcbdd8
...@@ -15,7 +15,6 @@ module Gitlab ...@@ -15,7 +15,6 @@ module Gitlab
@global = Node::Global.new(@config) @global = Node::Global.new(@config)
@global.process! @global.process!
@global.validate!
end end
def valid? def valid?
......
...@@ -8,13 +8,13 @@ module Gitlab ...@@ -8,13 +8,13 @@ module Gitlab
class Entry class Entry
class InvalidError < StandardError; end class InvalidError < StandardError; end
attr_reader :config, :attributes attr_reader :config, :metadata
attr_accessor :key, :parent, :description attr_accessor :key, :parent, :description
def initialize(config, **metadata) def initialize(config, **metadata)
@config = config @config = config
@entries = {}
@metadata = metadata @metadata = metadata
@entries = {}
@validator = self.class.validator.new(self) @validator = self.class.validator.new(self)
@validator.validate(:new) @validator.validate(:new)
...@@ -27,13 +27,6 @@ module Gitlab ...@@ -27,13 +27,6 @@ module Gitlab
@entries.each_value(&:process!) @entries.each_value(&:process!)
end end
def validate!
return unless valid?
@validator.validate(:processed)
@entries.each_value(&:validate!)
end
def leaf? def leaf?
nodes.none? nodes.none?
end end
......
...@@ -36,19 +36,13 @@ module Gitlab ...@@ -36,19 +36,13 @@ module Gitlab
helpers :before_script, :image, :services, :after_script, helpers :before_script, :image, :services, :after_script,
:variables, :stages, :types, :cache, :jobs :variables, :stages, :types, :cache, :jobs
def initialize(*)
super
@global = self
end
private private
def compose! def compose!
super super
compose_stages!
compose_jobs! compose_jobs!
compose_stages!
end end
def compose_jobs! def compose_jobs!
...@@ -65,9 +59,6 @@ module Gitlab ...@@ -65,9 +59,6 @@ module Gitlab
# Deprecated `:types` key workaround - if types are defined and # Deprecated `:types` key workaround - if types are defined and
# stages are not defined we use types definition as stages. # stages are not defined we use types definition as stages.
# #
# Otherwise we use stages in favor of types, and remove types from
# processing.
#
if types_defined? && !stages_defined? if types_defined? && !stages_defined?
@entries[:stages] = @entries[:types] @entries[:stages] = @entries[:types]
end end
......
...@@ -11,23 +11,21 @@ module Gitlab ...@@ -11,23 +11,21 @@ module Gitlab
validations do validations do
validates :config, type: Hash validates :config, type: Hash
with_options on: :processed do validate do
validate do unless has_visible_job?
unless has_visible_job? errors.add(:config, 'should contain at least one visible job')
errors.add(:config, 'should contain at least one visible job')
end
end end
end end
def has_visible_job?
config.any? { |key, _| !key.to_s.start_with?('.') }
end
end end
def nodes def nodes
@config @config
end end
def has_visible_job?
@entries.values.any?(&:relevant?)
end
private private
def create(name, config) def create(name, config)
......
...@@ -3,10 +3,7 @@ require 'spec_helper' ...@@ -3,10 +3,7 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Node::Job do describe Gitlab::Ci::Config::Node::Job do
let(:entry) { described_class.new(config, name: :rspec) } let(:entry) { described_class.new(config, name: :rspec) }
before do before { entry.process! }
entry.process!
entry.validate!
end
describe 'validations' do describe 'validations' do
context 'when entry config value is correct' do context 'when entry config value is correct' do
......
...@@ -4,10 +4,7 @@ describe Gitlab::Ci::Config::Node::Jobs do ...@@ -4,10 +4,7 @@ describe Gitlab::Ci::Config::Node::Jobs do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
before do before { entry.process! }
entry.process!
entry.validate!
end
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } } let(:config) { { rspec: { script: 'rspec' } } }
......
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