Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci/build_dependencies.rb')
-rw-r--r--app/models/ci/build_dependencies.rb85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/models/ci/build_dependencies.rb b/app/models/ci/build_dependencies.rb
new file mode 100644
index 00000000000..b5d67ef8e96
--- /dev/null
+++ b/app/models/ci/build_dependencies.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+module Ci
+ class BuildDependencies
+ attr_reader :processable
+
+ def initialize(processable)
+ @processable = processable
+ end
+
+ def all
+ (local + cross_pipeline).uniq
+ end
+
+ # Dependencies local to the given pipeline
+ def local
+ return [] if no_local_dependencies_specified?
+
+ deps = model_class.where(pipeline_id: processable.pipeline_id).latest
+ deps = from_previous_stages(deps)
+ deps = from_needs(deps)
+ deps = from_dependencies(deps)
+ deps
+ end
+
+ # Dependencies that are defined in other pipelines
+ def cross_pipeline
+ []
+ end
+
+ def invalid_local
+ local.reject(&:valid_dependency?)
+ end
+
+ def valid?
+ valid_local? && valid_cross_pipeline?
+ end
+
+ private
+
+ # Dependencies can only be of Ci::Build type because only builds
+ # can create artifacts
+ def model_class
+ ::Ci::Build
+ end
+
+ def valid_local?
+ return true if Feature.enabled?('ci_disable_validates_dependencies')
+
+ local.all?(&:valid_dependency?)
+ end
+
+ def valid_cross_pipeline?
+ true
+ end
+
+ def project
+ processable.project
+ end
+
+ def no_local_dependencies_specified?
+ processable.options[:dependencies]&.empty?
+ end
+
+ def from_previous_stages(scope)
+ scope.before_stage(processable.stage_idx)
+ end
+
+ def from_needs(scope)
+ return scope unless Feature.enabled?(:ci_dag_support, project, default_enabled: true)
+ return scope unless processable.scheduling_type_dag?
+
+ needs_names = processable.needs.artifacts.select(:name)
+ scope.where(name: needs_names)
+ end
+
+ def from_dependencies(scope)
+ return scope unless processable.options[:dependencies].present?
+
+ scope.where(name: processable.options[:dependencies])
+ end
+ end
+end
+
+Ci::BuildDependencies.prepend_if_ee('EE::Ci::BuildDependencies')