diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/jobs.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/normalizer.rb | 51 |
2 files changed, 52 insertions, 9 deletions
diff --git a/lib/gitlab/ci/config/entry/jobs.rb b/lib/gitlab/ci/config/entry/jobs.rb index fc4b8637ee2..1eab5927b56 100644 --- a/lib/gitlab/ci/config/entry/jobs.rb +++ b/lib/gitlab/ci/config/entry/jobs.rb @@ -29,15 +29,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def compose!(deps = nil) super do - @config = @config.map do |name, config| - total = config[:parallel] - if total - Array.new(total) { { name => config } } - .each_with_index { |build, idx| build["#{name} #{idx + 1}/#{total}".to_sym] = build.delete(name) } - else - { name => config } - end - end.flatten.reduce(:merge) + @config = Ci::Config::Normalizer.normalize_jobs(@config) @config.each do |name, config| node = hidden?(name) ? Entry::Hidden : Entry::Job diff --git a/lib/gitlab/ci/config/normalizer.rb b/lib/gitlab/ci/config/normalizer.rb new file mode 100644 index 00000000000..aa69dd44c5f --- /dev/null +++ b/lib/gitlab/ci/config/normalizer.rb @@ -0,0 +1,51 @@ +module Gitlab + module Ci + class Config + class Normalizer + class << self + def normalize_jobs(jobs_config) + parallelized_jobs = {} + + parallelized_config = jobs_config.map do |name, config| + if config&.[](:parallel) + total = config[:parallel] + names = parallelize_job_names(name, total) + parallelized_jobs[name] = names + Hash[names.collect { |job_name| [job_name.to_sym, config] }] + else + { name => config } + end + end.reduce(:merge) + + parallelized_config.each do |name, config| + next unless config[:dependencies] + + deps = config[:dependencies].map do |dep| + if parallelized_jobs.keys.include?(dep.to_sym) + config[:dependencies].delete(dep) + parallelized_jobs[dep.to_sym] + else + dep + end + end.flatten + + config[:dependencies] = deps + end + end + + private + + def parallelize_job_names(name, total) + jobs = [] + + total.times do |idx| + jobs << "#{name} #{idx + 1}/#{total}" + end + + jobs + end + end + end + end + end +end |