debian-mirror-gitlab/lib/gitlab/ci/yaml_processor/dag.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
716 B
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
# Represents Dag pipeline
module Gitlab
module Ci
class YamlProcessor
class Dag
include TSort
def initialize(nodes)
@nodes = nodes
end
2022-05-07 20:08:51 +05:30
def self.order(jobs)
new(jobs).tsort
end
2021-09-30 23:02:18 +05:30
2022-05-07 20:08:51 +05:30
def self.check_circular_dependencies!(jobs)
new(jobs).tsort
2021-09-30 23:02:18 +05:30
rescue TSort::Cyclic
2021-10-27 15:23:28 +05:30
raise ValidationError, 'The pipeline has circular dependencies'
2021-09-30 23:02:18 +05:30
end
def tsort_each_child(node, &block)
2022-05-07 20:08:51 +05:30
return unless @nodes[node]
2021-09-30 23:02:18 +05:30
@nodes[node].each(&block)
end
def tsort_each_node(&block)
@nodes.each_key(&block)
end
end
end
end
end