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

dependencies.rb « processable « ci « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d42ac4dc00733d28cb231dcf08204b364adfa37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true

module Ci
  class Processable
    class Dependencies
      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
end

Ci::Processable::Dependencies.prepend_if_ee('EE::Ci::Processable::Dependencies')