debian-mirror-gitlab/lib/gitlab/ci/config/normalizer/matrix_strategy.rb

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

68 lines
1.6 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
class Normalizer
class MatrixStrategy
class << self
def applies_to?(config)
config.is_a?(Hash) && config.key?(:matrix)
end
def build_from(job_name, initial_config)
config = expand(initial_config[:matrix])
total = config.size
config.map.with_index do |vars, index|
new(job_name, index.next, vars, total)
end
end
# rubocop: disable CodeReuse/ActiveRecord
def expand(config)
config.flat_map do |config|
values = config.values
values[0]
.product(*values.from(1))
.map { |vals| config.keys.zip(vals).to_h }
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
def initialize(job_name, instance, variables, total)
@job_name = job_name
@instance = instance
@variables = variables.to_h
@total = total
end
def attributes
{
name: name,
instance: instance,
2021-04-29 21:17:54 +05:30
job_variables: variables,
2020-10-24 23:57:45 +05:30
parallel: { total: total }
2021-04-29 21:17:54 +05:30
}.compact
2020-10-24 23:57:45 +05:30
end
def name
2020-11-24 15:15:51 +05:30
vars = variables
.values
.compact
.join(', ')
"#{job_name}: [#{vars}]"
2020-10-24 23:57:45 +05:30
end
private
attr_reader :job_name, :instance, :variables, :total
end
end
end
end
end