From 684751d3c2233ee1ac33cf623e8b7822c60209d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Fri, 2 Aug 2019 16:32:52 +0200 Subject: Make needs: to require previous jobs This changes `needs:` from weak reference to have a strong reference. This means that job will not be created unless all needs are present as part of a pipeline. --- lib/gitlab/ci/pipeline/seed/build.rb | 31 ++++++++++++++++++++++++++++--- lib/gitlab/ci/pipeline/seed/stage.rb | 19 ++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index d8296940a04..ab0d4c38ab6 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -9,9 +9,10 @@ module Gitlab delegate :dig, to: :@attributes - def initialize(pipeline, attributes) + def initialize(pipeline, attributes, previous_stages) @pipeline = pipeline @attributes = attributes + @previous_stages = previous_stages @only = Gitlab::Ci::Build::Policy .fabricate(attributes.delete(:only)) @@ -19,10 +20,15 @@ module Gitlab .fabricate(attributes.delete(:except)) end + def name + dig(:name) + end + def included? strong_memoize(:inclusion) do - @only.all? { |spec| spec.satisfied_by?(@pipeline, self) } && - @except.none? { |spec| spec.satisfied_by?(@pipeline, self) } + all_of_only? && + none_of_except? && + all_of_needs? end end @@ -42,6 +48,25 @@ module Gitlab @attributes.to_h.dig(:options, :trigger).present? end + def all_of_only? + @only.all? { |spec| spec.satisfied_by?(@pipeline, self) } + end + + def none_of_except? + @except.none? { |spec| spec.satisfied_by?(@pipeline, self) } + end + + def all_of_needs? + return true unless Feature.enabled?(:ci_dag_support, @pipeline.project) + return true if dig(:needs_attributes).nil? + + dig(:needs_attributes).all? do |need| + @previous_stages.any? do |stage| + stage.seeds_names.include?(need[:name]) + end + end + end + def to_resource strong_memoize(:resource) do if bridge? diff --git a/lib/gitlab/ci/pipeline/seed/stage.rb b/lib/gitlab/ci/pipeline/seed/stage.rb index 9c15064756a..7c737027445 100644 --- a/lib/gitlab/ci/pipeline/seed/stage.rb +++ b/lib/gitlab/ci/pipeline/seed/stage.rb @@ -10,12 +10,13 @@ module Gitlab delegate :size, to: :seeds delegate :dig, to: :seeds - def initialize(pipeline, attributes) + def initialize(pipeline, attributes, previous_stages) @pipeline = pipeline @attributes = attributes + @previous_stages = previous_stages @builds = attributes.fetch(:builds).map do |attributes| - Seed::Build.new(@pipeline, attributes) + Seed::Build.new(@pipeline, attributes, previous_stages) end end @@ -32,6 +33,12 @@ module Gitlab end end + def seeds_names + strong_memoize(:seeds_names) do + seeds.map(&:name).to_set + end + end + def included? seeds.any? end @@ -39,13 +46,7 @@ module Gitlab def to_resource strong_memoize(:stage) do ::Ci::Stage.new(attributes).tap do |stage| - seeds.each do |seed| - if seed.bridge? - stage.bridges << seed.to_resource - else - stage.builds << seed.to_resource - end - end + stage.statuses = seeds.map(&:to_resource) end end end -- cgit v1.2.1