Commit 000f9d01 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Decouple YAML processor from pipeline objects

parent 0e51842d
...@@ -362,7 +362,13 @@ module Ci ...@@ -362,7 +362,13 @@ module Ci
def stage_seeds def stage_seeds
return [] unless config_processor return [] unless config_processor
@stage_seeds ||= config_processor.stage_seeds(self) strong_memoize(:stage_seeds) do
seeds = config_processor.stages.map do |attributes|
Gitlab::Ci::Pipeline::Seed::Stage.new(self, attributes)
end
seeds.select(&:included?)
end
end end
def has_kubernetes_active? def has_kubernetes_active?
......
...@@ -53,60 +53,40 @@ module Gitlab ...@@ -53,60 +53,40 @@ module Gitlab
}.compact } }.compact }
end end
# REFACTORING, this needs improvement # REFACTORING, this needs improvement, and specs
# #
def build_seed_attributes(stage) def stage_attributes(stage)
selected = @jobs.values.select do |job| selected = @jobs.values.select do |job|
job[:stage] == stage job[:stage] == stage
end end
selected.map do |job| selected.map do |job|
build_attributes(job[:name]) build_attributes(job[:name])
.merge(only: job.fetch(:only, {}))
.merge(except: job.fetch(:except, {}))
end end
end end
# REFACTORING, slated for removal # REFACTORING, needs specs
# #
def pipeline_stage_builds(stage, pipeline) def seed_attributes(stage)
selected_jobs = @jobs.select do |_, job| seeds = stage_attributes(stage).map do |attributes|
next unless job[:stage] == stage job = @jobs.fetch(attributes[:name].to_sym)
only_specs = Gitlab::Ci::Build::Policy
.fabricate(job.fetch(:only, {}))
except_specs = Gitlab::Ci::Build::Policy
.fabricate(job.fetch(:except, {}))
only_specs.all? { |spec| spec.satisfied_by?(pipeline) } &&
except_specs.none? { |spec| spec.satisfied_by?(pipeline) }
end
selected_jobs.map { |_, job| build_attributes(job[:name]) } attributes
.merge(only: job.fetch(:only, {}))
.merge(except: job.fetch(:except, {}))
end end
def stage_seed_attributes(stage)
{ name: stage, { name: stage,
index: @stages.index(stage), index: @stages.index(stage),
builds: build_seed_attributes(stage) } builds: seeds }
end end
# REFACTORING, slated for removal # REFACTORING, needs specs
# * WARNING this method is currently evaluating only/except policies
# in two places - Seed::Build, and in pipeline_stage_builds
# * WARNING it needs to be refactored to use SSOT
# #
def stage_seeds(pipeline) def stages
seeds = @stages.uniq.map do |stage| @stages.uniq.map do |stage|
builds = pipeline_stage_builds(stage, pipeline) seed_attributes(stage)
if builds.any?
Gitlab::Ci::Pipeline::Seed::Stage
.new(pipeline, stage_seed_attributes(stage))
end
end end
seeds.compact
end end
def self.validation_message(content) def self.validation_message(content)
......
...@@ -203,7 +203,7 @@ module Gitlab ...@@ -203,7 +203,7 @@ module Gitlab
let(:config_data) { YAML.dump(config) } let(:config_data) { YAML.dump(config) }
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config_data) } let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config_data) }
subject { config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first } subject { config_processor.stage_attributes('test').first }
describe "before_script" do describe "before_script" do
context "in global context" do context "in global context" do
...@@ -286,8 +286,8 @@ module Gitlab ...@@ -286,8 +286,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({ expect(config_processor.stage_attributes("test").first).to eq({
stage: "test", stage: "test",
stage_idx: 1, stage_idx: 1,
name: "rspec", name: "rspec",
...@@ -321,8 +321,8 @@ module Gitlab ...@@ -321,8 +321,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({ expect(config_processor.stage_attributes("test").first).to eq({
stage: "test", stage: "test",
stage_idx: 1, stage_idx: 1,
name: "rspec", name: "rspec",
...@@ -354,8 +354,8 @@ module Gitlab ...@@ -354,8 +354,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({ expect(config_processor.stage_attributes("test").first).to eq({
stage: "test", stage: "test",
stage_idx: 1, stage_idx: 1,
name: "rspec", name: "rspec",
...@@ -383,8 +383,8 @@ module Gitlab ...@@ -383,8 +383,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({ expect(config_processor.stage_attributes("test").first).to eq({
stage: "test", stage: "test",
stage_idx: 1, stage_idx: 1,
name: "rspec", name: "rspec",
...@@ -529,8 +529,8 @@ module Gitlab ...@@ -529,8 +529,8 @@ module Gitlab
}) })
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
builds = config_processor.stage_attributes("test")
builds = config_processor.pipeline_stage_builds("test", pipeline(ref: "master"))
expect(builds.size).to eq(1) expect(builds.size).to eq(1)
expect(builds.first[:when]).to eq(when_state) expect(builds.first[:when]).to eq(when_state)
end end
...@@ -561,8 +561,8 @@ module Gitlab ...@@ -561,8 +561,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq( expect(config_processor.stage_attributes("test").first[:options][:cache]).to eq(
paths: ["logs/", "binaries/"], paths: ["logs/", "binaries/"],
untracked: true, untracked: true,
key: 'key', key: 'key',
...@@ -580,8 +580,8 @@ module Gitlab ...@@ -580,8 +580,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq( expect(config_processor.stage_attributes("test").first[:options][:cache]).to eq(
paths: ["logs/", "binaries/"], paths: ["logs/", "binaries/"],
untracked: true, untracked: true,
key: 'key', key: 'key',
...@@ -600,8 +600,8 @@ module Gitlab ...@@ -600,8 +600,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first[:options][:cache]).to eq( expect(config_processor.stage_attributes("test").first[:options][:cache]).to eq(
paths: ["test/"], paths: ["test/"],
untracked: false, untracked: false,
key: 'local', key: 'local',
...@@ -629,8 +629,8 @@ module Gitlab ...@@ -629,8 +629,8 @@ module Gitlab
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).size).to eq(1) expect(config_processor.stage_attributes("test").size).to eq(1)
expect(config_processor.pipeline_stage_builds("test", pipeline(ref: "master")).first).to eq({ expect(config_processor.stage_attributes("test").first).to eq({
stage: "test", stage: "test",
stage_idx: 1, stage_idx: 1,
name: "rspec", name: "rspec",
...@@ -666,8 +666,8 @@ module Gitlab ...@@ -666,8 +666,8 @@ module Gitlab
}) })
config_processor = Gitlab::Ci::YamlProcessor.new(config) config_processor = Gitlab::Ci::YamlProcessor.new(config)
builds = config_processor.stage_attributes("test")
builds = config_processor.pipeline_stage_builds("test", pipeline(ref: "master"))
expect(builds.size).to eq(1) expect(builds.size).to eq(1)
expect(builds.first[:options][:artifacts][:when]).to eq(when_state) expect(builds.first[:options][:artifacts][:when]).to eq(when_state)
end end
...@@ -682,7 +682,7 @@ module Gitlab ...@@ -682,7 +682,7 @@ module Gitlab
end end
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) } let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
let(:builds) { processor.pipeline_stage_builds('deploy', pipeline(ref: 'master')) } let(:builds) { processor.stage_attributes('deploy') }
context 'when a production environment is specified' do context 'when a production environment is specified' do
let(:environment) { 'production' } let(:environment) { 'production' }
...@@ -839,7 +839,7 @@ module Gitlab ...@@ -839,7 +839,7 @@ module Gitlab
describe "Hidden jobs" do describe "Hidden jobs" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) } let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) }
subject { config_processor.pipeline_stage_builds("test", pipeline(ref: "master")) } subject { config_processor.stage_attributes("test") }
shared_examples 'hidden_job_handling' do shared_examples 'hidden_job_handling' do
it "doesn't create jobs that start with dot" do it "doesn't create jobs that start with dot" do
...@@ -887,7 +887,7 @@ module Gitlab ...@@ -887,7 +887,7 @@ module Gitlab
describe "YAML Alias/Anchor" do describe "YAML Alias/Anchor" do
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) } let(:config_processor) { Gitlab::Ci::YamlProcessor.new(config) }
subject { config_processor.pipeline_stage_builds("build", pipeline(ref: "master")) } subject { config_processor.stage_attributes("build") }
shared_examples 'job_templates_handling' do shared_examples 'job_templates_handling' do
it "is correctly supported for jobs" do it "is correctly supported for jobs" 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