lib/buildkite/builder/extensions/steps.rb in buildkite-builder-3.9.0 vs lib/buildkite/builder/extensions/steps.rb in buildkite-builder-4.0.0
- old
+ new
@@ -1,56 +1,78 @@
module Buildkite
module Builder
module Extensions
class Steps < Extension
+ attr_reader :templates
+
def prepare
- context.data.steps = StepCollection.new(TemplateManager.new(context.root))
+ @templates = TemplateManager.new(context.root)
+ context.data.steps = StepCollection.new
end
- dsl do
- def group(label = nil, emoji: nil, &block)
- raise "Group does not allow nested in another Group" if context.is_a?(Group)
+ def build_step(step_class, template_name, **args, &block)
+ template = @templates.find(template_name)
- if emoji
- emoji = Array(emoji).map { |name| ":#{name}:" }.join
- label = [emoji, label].compact.join(' ')
+ step_class.new(**args).tap do |step|
+ step.process(template) if template
+ step.process(block) if block_given?
+
+ if @current_group
+ @current_group.steps.push(step)
+ else
+ context.data.steps.push(step)
end
+ end
+ end
- context.data.steps.push(Buildkite::Builder::Group.new(label, context, &block))
+ def with_group(group, &block)
+ raise "Group cannot be nested" if @current_group
+
+ @current_group = group
+
+ group.process(block)
+ context.data.steps.push(group).last
+ ensure
+ @current_group = nil
+ end
+
+ dsl do
+ def group(&block)
+ context.extensions.find(Steps).with_group(Pipelines::Steps::Group.new(context), &block)
end
def block(template = nil, **args, &block)
- context.data.steps.add(Pipelines::Steps::Block, template, **args, &block)
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Block, template, **args, &block)
end
def command(template = nil, **args, &block)
- context.data.steps.add(Pipelines::Steps::Command, template, **args, &block)
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Command, template, **args, &block)
end
def input(template = nil, **args, &block)
- context.data.steps.add(Pipelines::Steps::Input, template, **args, &block)
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Input, template, **args, &block)
end
def trigger(template = nil, **args, &block)
- context.data.steps.add(Pipelines::Steps::Trigger, template, **args, &block)
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Trigger, template, **args, &block)
end
def skip(template = nil, **args, &block)
- step = context.data.steps.add(Pipelines::Steps::Skip, template, **args, &block)
- # A skip step has a nil/noop command.
- step.command(nil)
- # Always set the skip attribute if it's in a falsey state.
- step.skip(true) if !step.get(:skip) || step.skip.empty?
- step
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Skip, template, **args, &block).tap do |step|
+ # A skip step has a nil/noop command.
+ step.command(nil)
+ # Always set the skip attribute if it's in a falsey state.
+ step.skip(true) if !step.get(:skip) || step.skip.empty?
+ end
end
def wait(attributes = {}, &block)
- step = context.data.steps.add(Pipelines::Steps::Wait, &block)
- step.wait(nil)
- attributes.each do |key, value|
- step.set(key, value)
+ context.extensions.find(Steps).build_step(Pipelines::Steps::Wait, nil, &block).tap do |step|
+ step.wait(nil)
+ attributes.each do |key, value|
+ step.set(key, value)
+ end
end
- step
end
end
end
end
end