buildkite-builder 3.9.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -30
- data/VERSION +1 -1
- data/lib/buildkite/builder/extension.rb +2 -2
- data/lib/buildkite/builder/extension_manager.rb +5 -1
- data/lib/buildkite/builder/extensions/plugins.rb +0 -11
- data/lib/buildkite/builder/extensions/steps.rb +39 -26
- data/lib/buildkite/builder/extensions.rb +0 -1
- data/lib/buildkite/builder/pipeline.rb +0 -3
- data/lib/buildkite/builder/step_collection.rb +29 -18
- data/lib/buildkite/builder/template_manager.rb +0 -4
- data/lib/buildkite/builder.rb +0 -1
- data/lib/buildkite/pipelines/steps/abstract.rb +4 -8
- data/lib/buildkite/pipelines/steps/group.rb +37 -0
- data/lib/buildkite/pipelines/steps.rb +1 -1
- metadata +3 -6
- data/lib/buildkite/builder/extensions/sub_pipelines.rb +0 -104
- data/lib/buildkite/builder/group.rb +0 -41
- data/lib/buildkite/builder/pipeline_collection.rb +0 -40
- data/lib/buildkite/pipelines/steps/skip.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1f1ed1d180d7e0682417a8ada846785b485c32af561a442c9d2e6370975de1f
|
|
4
|
+
data.tar.gz: c618bcd175b11c4dccb1b1f40d642ce7286b05b5c5d9fd42693e060d0602c2f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e45d32dfedd02df0fba24ba0ac59ae388dc4c4d909e26c7fa6672944ba637959352a73619b6629b9d5ea3c89b94a974f93a1c50c182a08bf9ede5092438fb52
|
|
7
|
+
data.tar.gz: d428745b5ffd07191f5bcd375ff7aaa4043ccc2fda09733c3569f34658b377b00cdd63d3ea8b46c0d1ce28524519a6c9701e44c720afee4c9393da8f4d4de17d
|
data/README.md
CHANGED
|
@@ -135,36 +135,6 @@ Buildkite::Builder.pipeline do
|
|
|
135
135
|
end
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
### Subpipeline
|
|
139
|
-
|
|
140
|
-
While triggering another pipeline, you can predefine subpipeline's steps using `pipeline(NAME_OF_SUBPIPELINE)` in the main pipeline's `pipeline.rb` file and share with main pipeline's plugins and templates definition.
|
|
141
|
-
|
|
142
|
-
`.buildkite/pipelines/pipeline-triggerer/pipeline.rb`
|
|
143
|
-
|
|
144
|
-
```ruby
|
|
145
|
-
Buildkite::Builder.pipeline do
|
|
146
|
-
pipeline('rspec-pipeline') do
|
|
147
|
-
command do
|
|
148
|
-
label "Run RSpec in separate pipeline"
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Inside your Buildkite pipeline setup, you can do the following:
|
|
155
|
-
|
|
156
|
-
In `https://buildkite.com/your-org/rspec-pipeline/steps`
|
|
157
|
-
|
|
158
|
-
```yaml
|
|
159
|
-
steps:
|
|
160
|
-
- label: ":pipeline:"
|
|
161
|
-
commands:
|
|
162
|
-
- buildkite-agent artifact download $BKB_SUBPIPELINE_FILE . --build $BUILDKITE_TRIGGERED_FROM_BUILD_ID
|
|
163
|
-
- buildkite-agent pipeline upload $BKB_SUBPIPELINE_FILE
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
This will upload the pregenerated `pipeline.yml` to `rspec-pipeline`.
|
|
167
|
-
|
|
168
138
|
## Development
|
|
169
139
|
|
|
170
140
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.1.0
|
|
@@ -14,12 +14,12 @@ module Buildkite
|
|
|
14
14
|
|
|
15
15
|
attr_reader :context
|
|
16
16
|
attr_reader :options
|
|
17
|
-
attr_reader :
|
|
17
|
+
attr_reader :options_block
|
|
18
18
|
|
|
19
19
|
def initialize(context, **options, &block)
|
|
20
20
|
@context = context
|
|
21
21
|
@options = options
|
|
22
|
-
@
|
|
22
|
+
@options_block = block
|
|
23
23
|
|
|
24
24
|
prepare
|
|
25
25
|
end
|
|
@@ -8,7 +8,7 @@ module Buildkite
|
|
|
8
8
|
@context = context
|
|
9
9
|
@extensions = {}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Loaders::Extensions.load(@context.root)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def use(extension, native: false, **args, &block)
|
|
@@ -34,6 +34,10 @@ module Buildkite
|
|
|
34
34
|
@extensions.fetch(klass)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def all
|
|
38
|
+
@extensions.keys
|
|
39
|
+
end
|
|
40
|
+
|
|
37
41
|
private
|
|
38
42
|
|
|
39
43
|
def log
|
|
@@ -23,17 +23,6 @@ module Buildkite
|
|
|
23
23
|
resource.is_a?(Symbol) ? manager.build(resource, attributes) : plugin
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
|
|
27
|
-
context.data.pipelines.each do |pipeline|
|
|
28
|
-
pipeline.data.steps.each(:command) do |step|
|
|
29
|
-
next unless step.has?(:plugins)
|
|
30
|
-
|
|
31
|
-
step.get(:plugins).map! do |plugin|
|
|
32
|
-
resource, attributes = extract_resource_and_attributes(plugin)
|
|
33
|
-
resource.is_a?(Symbol) ? manager.build(resource, attributes) : plugin
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
26
|
end
|
|
38
27
|
|
|
39
28
|
private
|
|
@@ -2,54 +2,67 @@ module Buildkite
|
|
|
2
2
|
module Builder
|
|
3
3
|
module Extensions
|
|
4
4
|
class Steps < Extension
|
|
5
|
+
attr_reader :templates
|
|
6
|
+
|
|
5
7
|
def prepare
|
|
6
|
-
|
|
8
|
+
@templates = TemplateManager.new(context.root)
|
|
9
|
+
context.data.steps = StepCollection.new
|
|
7
10
|
end
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
def build_step(step_class, template_name, **args, &block)
|
|
13
|
+
template = @templates.find(template_name)
|
|
14
|
+
|
|
15
|
+
step_class.new(**args).tap do |step|
|
|
16
|
+
step.process(template) if template
|
|
17
|
+
step.process(block) if block_given?
|
|
12
18
|
|
|
13
|
-
if
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
if @current_group
|
|
20
|
+
@current_group.steps.push(step)
|
|
21
|
+
else
|
|
22
|
+
context.data.steps.push(step)
|
|
16
23
|
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def with_group(group, &block)
|
|
28
|
+
raise "Group cannot be nested" if @current_group
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
@current_group = group
|
|
31
|
+
|
|
32
|
+
group.process(block)
|
|
33
|
+
context.data.steps.push(group).last
|
|
34
|
+
ensure
|
|
35
|
+
@current_group = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
dsl do
|
|
39
|
+
def group(&block)
|
|
40
|
+
context.extensions.find(Steps).with_group(Pipelines::Steps::Group.new(context), &block)
|
|
19
41
|
end
|
|
20
42
|
|
|
21
43
|
def block(template = nil, **args, &block)
|
|
22
|
-
context.
|
|
44
|
+
context.extensions.find(Steps).build_step(Pipelines::Steps::Block, template, **args, &block)
|
|
23
45
|
end
|
|
24
46
|
|
|
25
47
|
def command(template = nil, **args, &block)
|
|
26
|
-
context.
|
|
48
|
+
context.extensions.find(Steps).build_step(Pipelines::Steps::Command, template, **args, &block)
|
|
27
49
|
end
|
|
28
50
|
|
|
29
51
|
def input(template = nil, **args, &block)
|
|
30
|
-
context.
|
|
52
|
+
context.extensions.find(Steps).build_step(Pipelines::Steps::Input, template, **args, &block)
|
|
31
53
|
end
|
|
32
54
|
|
|
33
55
|
def trigger(template = nil, **args, &block)
|
|
34
|
-
context.
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def skip(template = nil, **args, &block)
|
|
38
|
-
step = context.data.steps.add(Pipelines::Steps::Skip, template, **args, &block)
|
|
39
|
-
# A skip step has a nil/noop command.
|
|
40
|
-
step.command(nil)
|
|
41
|
-
# Always set the skip attribute if it's in a falsey state.
|
|
42
|
-
step.skip(true) if !step.get(:skip) || step.skip.empty?
|
|
43
|
-
step
|
|
56
|
+
context.extensions.find(Steps).build_step(Pipelines::Steps::Trigger, template, **args, &block)
|
|
44
57
|
end
|
|
45
58
|
|
|
46
59
|
def wait(attributes = {}, &block)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
context.extensions.find(Steps).build_step(Pipelines::Steps::Wait, nil, &block).tap do |step|
|
|
61
|
+
step.wait(nil)
|
|
62
|
+
attributes.each do |key, value|
|
|
63
|
+
step.set(key, value)
|
|
64
|
+
end
|
|
51
65
|
end
|
|
52
|
-
step
|
|
53
66
|
end
|
|
54
67
|
end
|
|
55
68
|
end
|
|
@@ -6,7 +6,6 @@ module Buildkite
|
|
|
6
6
|
autoload :Env, File.expand_path('extensions/env', __dir__)
|
|
7
7
|
autoload :Lib, File.expand_path('extensions/lib', __dir__)
|
|
8
8
|
autoload :Notify, File.expand_path('extensions/notify', __dir__)
|
|
9
|
-
autoload :SubPipelines, File.expand_path('extensions/sub_pipelines', __dir__)
|
|
10
9
|
autoload :Steps, File.expand_path('extensions/steps', __dir__)
|
|
11
10
|
autoload :Plugins, File.expand_path('extensions/plugins', __dir__)
|
|
12
11
|
autoload :Use, File.expand_path('extensions/use', __dir__)
|
|
@@ -19,7 +19,6 @@ module Buildkite
|
|
|
19
19
|
attr_reader :logger,
|
|
20
20
|
:root,
|
|
21
21
|
:artifacts,
|
|
22
|
-
:plugins,
|
|
23
22
|
:dsl,
|
|
24
23
|
:data,
|
|
25
24
|
:extensions
|
|
@@ -28,7 +27,6 @@ module Buildkite
|
|
|
28
27
|
@root = root
|
|
29
28
|
@logger = logger || Logger.new(File::NULL)
|
|
30
29
|
@artifacts = []
|
|
31
|
-
@plugins = {}
|
|
32
30
|
@dsl = Dsl.new(self)
|
|
33
31
|
@extensions = ExtensionManager.new(self)
|
|
34
32
|
@data = Data.new
|
|
@@ -39,7 +37,6 @@ module Buildkite
|
|
|
39
37
|
use(Extensions::Notify)
|
|
40
38
|
use(Extensions::Steps)
|
|
41
39
|
use(Extensions::Plugins)
|
|
42
|
-
use(Extensions::SubPipelines)
|
|
43
40
|
end
|
|
44
41
|
|
|
45
42
|
def upload
|
|
@@ -1,40 +1,51 @@
|
|
|
1
1
|
module Buildkite
|
|
2
2
|
module Builder
|
|
3
3
|
class StepCollection
|
|
4
|
-
|
|
4
|
+
STEP_TYPES = {
|
|
5
|
+
block: Pipelines::Steps::Block,
|
|
6
|
+
command: Pipelines::Steps::Command,
|
|
7
|
+
group: Pipelines::Steps::Group,
|
|
8
|
+
input: Pipelines::Steps::Input,
|
|
9
|
+
trigger: Pipelines::Steps::Trigger,
|
|
10
|
+
wait: Pipelines::Steps::Wait
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
5
13
|
attr_reader :steps
|
|
6
14
|
|
|
7
|
-
def initialize
|
|
8
|
-
@templates = templates
|
|
15
|
+
def initialize
|
|
9
16
|
@steps = []
|
|
10
17
|
end
|
|
11
18
|
|
|
12
|
-
def each(*types)
|
|
19
|
+
def each(*types, &block)
|
|
13
20
|
types = types.flatten
|
|
21
|
+
types.map! { |type| STEP_TYPES.values.include?(type) ? type : STEP_TYPES.fetch(type) }
|
|
22
|
+
types = STEP_TYPES.values if types.empty?
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
if types.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
elsif types.empty?
|
|
23
|
-
yield step
|
|
24
|
+
matched_steps = steps.each_with_object([]) do |step, matches|
|
|
25
|
+
if types.any? { |step_type| step.is_a?(step_type) }
|
|
26
|
+
matches << step
|
|
27
|
+
end
|
|
28
|
+
if step.is_a?(Pipelines::Steps::Group)
|
|
29
|
+
step.steps.each(types) { |step| matches << step }
|
|
24
30
|
end
|
|
25
31
|
end
|
|
32
|
+
matched_steps.each(&block)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
def find(key)
|
|
29
|
-
|
|
36
|
+
steps.find { |step| step.has?(:key) && step.key.to_s == key.to_s }
|
|
30
37
|
end
|
|
31
38
|
|
|
32
|
-
def
|
|
33
|
-
|
|
39
|
+
def remove(step)
|
|
40
|
+
steps.delete(step)
|
|
34
41
|
end
|
|
35
42
|
|
|
36
|
-
def
|
|
37
|
-
|
|
43
|
+
def replace(old_step, new_step)
|
|
44
|
+
steps[steps.index(old_step)] = new_step
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def find!(key)
|
|
48
|
+
find(key) || raise(ArgumentError, "Can't find step with key: #{key}")
|
|
38
49
|
end
|
|
39
50
|
|
|
40
51
|
def push(step)
|
data/lib/buildkite/builder.rb
CHANGED
|
@@ -5,7 +5,6 @@ require 'pathname'
|
|
|
5
5
|
module Buildkite
|
|
6
6
|
module Builder
|
|
7
7
|
autoload :Commands, File.expand_path('builder/commands', __dir__)
|
|
8
|
-
autoload :Group, File.expand_path('builder/group', __dir__)
|
|
9
8
|
autoload :Pipeline, File.expand_path('builder/pipeline', __dir__)
|
|
10
9
|
autoload :Definition, File.expand_path('builder/definition', __dir__)
|
|
11
10
|
autoload :Data, File.expand_path('builder/data', __dir__)
|
|
@@ -11,20 +11,16 @@ module Buildkite
|
|
|
11
11
|
|
|
12
12
|
def_delegator :@context, :data
|
|
13
13
|
|
|
14
|
-
attr_reader :template
|
|
15
|
-
attr_reader :step_collection
|
|
16
|
-
|
|
17
14
|
def self.to_sym
|
|
18
15
|
name.split('::').last.downcase.to_sym
|
|
19
16
|
end
|
|
20
17
|
|
|
21
|
-
def initialize(
|
|
22
|
-
@step_collection = step_collection
|
|
23
|
-
@template = step_collection.templates.find(template_name)
|
|
18
|
+
def initialize(**args)
|
|
24
19
|
@context = StepContext.new(self, **args)
|
|
20
|
+
end
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
instance_exec(@context, &block)
|
|
22
|
+
def process(block)
|
|
23
|
+
instance_exec(@context, &block)
|
|
28
24
|
end
|
|
29
25
|
end
|
|
30
26
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Buildkite
|
|
4
|
+
module Pipelines
|
|
5
|
+
module Steps
|
|
6
|
+
class Group < Abstract
|
|
7
|
+
attribute :depends_on, append: true
|
|
8
|
+
attribute :key
|
|
9
|
+
attribute :label
|
|
10
|
+
|
|
11
|
+
attr_reader :steps
|
|
12
|
+
|
|
13
|
+
def initialize(pipeline, **args)
|
|
14
|
+
@pipeline = pipeline
|
|
15
|
+
@context = StepContext.new(self, **args)
|
|
16
|
+
@steps = Buildkite::Builder::StepCollection.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def method_missing(method_name, ...)
|
|
20
|
+
if @pipeline.dsl.respond_to?(method_name)
|
|
21
|
+
@pipeline.dsl.public_send(method_name, ...)
|
|
22
|
+
else
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def respond_to_missing?(...)
|
|
28
|
+
@pipeline.dsl.respond_to?(...) || super
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_h
|
|
32
|
+
super.merge(group: nil, steps: steps.to_definition)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -6,8 +6,8 @@ module Buildkite
|
|
|
6
6
|
autoload :Abstract, File.expand_path('steps/abstract', __dir__)
|
|
7
7
|
autoload :Block, File.expand_path('steps/block', __dir__)
|
|
8
8
|
autoload :Command, File.expand_path('steps/command', __dir__)
|
|
9
|
+
autoload :Group, File.expand_path('steps/group', __dir__)
|
|
9
10
|
autoload :Input, File.expand_path('steps/input', __dir__)
|
|
10
|
-
autoload :Skip, File.expand_path('steps/skip', __dir__)
|
|
11
11
|
autoload :Trigger, File.expand_path('steps/trigger', __dir__)
|
|
12
12
|
autoload :Wait, File.expand_path('steps/wait', __dir__)
|
|
13
13
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: buildkite-builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ngan Pham
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2022-12-
|
|
12
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rainbow
|
|
@@ -115,16 +115,13 @@ files:
|
|
|
115
115
|
- lib/buildkite/builder/extensions/notify.rb
|
|
116
116
|
- lib/buildkite/builder/extensions/plugins.rb
|
|
117
117
|
- lib/buildkite/builder/extensions/steps.rb
|
|
118
|
-
- lib/buildkite/builder/extensions/sub_pipelines.rb
|
|
119
118
|
- lib/buildkite/builder/extensions/use.rb
|
|
120
|
-
- lib/buildkite/builder/group.rb
|
|
121
119
|
- lib/buildkite/builder/loaders.rb
|
|
122
120
|
- lib/buildkite/builder/loaders/abstract.rb
|
|
123
121
|
- lib/buildkite/builder/loaders/extensions.rb
|
|
124
122
|
- lib/buildkite/builder/loaders/templates.rb
|
|
125
123
|
- lib/buildkite/builder/logging_utils.rb
|
|
126
124
|
- lib/buildkite/builder/pipeline.rb
|
|
127
|
-
- lib/buildkite/builder/pipeline_collection.rb
|
|
128
125
|
- lib/buildkite/builder/plugin.rb
|
|
129
126
|
- lib/buildkite/builder/plugin_manager.rb
|
|
130
127
|
- lib/buildkite/builder/rainbow.rb
|
|
@@ -150,8 +147,8 @@ files:
|
|
|
150
147
|
- lib/buildkite/pipelines/steps/abstract.rb
|
|
151
148
|
- lib/buildkite/pipelines/steps/block.rb
|
|
152
149
|
- lib/buildkite/pipelines/steps/command.rb
|
|
150
|
+
- lib/buildkite/pipelines/steps/group.rb
|
|
153
151
|
- lib/buildkite/pipelines/steps/input.rb
|
|
154
|
-
- lib/buildkite/pipelines/steps/skip.rb
|
|
155
152
|
- lib/buildkite/pipelines/steps/trigger.rb
|
|
156
153
|
- lib/buildkite/pipelines/steps/wait.rb
|
|
157
154
|
homepage: https://github.com/Gusto/buildkite-builder
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
require 'securerandom'
|
|
2
|
-
|
|
3
|
-
module Buildkite
|
|
4
|
-
module Builder
|
|
5
|
-
module Extensions
|
|
6
|
-
class SubPipelines < Extension
|
|
7
|
-
class Pipeline
|
|
8
|
-
include Buildkite::Pipelines::Attributes
|
|
9
|
-
|
|
10
|
-
attr_reader :data, :name, :dsl
|
|
11
|
-
|
|
12
|
-
# These attributes are for triggered step
|
|
13
|
-
attribute :label
|
|
14
|
-
attribute :key
|
|
15
|
-
attribute :skip
|
|
16
|
-
attribute :if, as: :condition
|
|
17
|
-
attribute :depends_on, append: true
|
|
18
|
-
attribute :allow_dependency_failure
|
|
19
|
-
attribute :branches
|
|
20
|
-
attribute :async
|
|
21
|
-
attribute :build
|
|
22
|
-
|
|
23
|
-
def self.to_sym
|
|
24
|
-
name.split('::').last.downcase.to_sym
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def initialize(name, context, &block)
|
|
28
|
-
@context = context
|
|
29
|
-
@name = name
|
|
30
|
-
@data = Data.new
|
|
31
|
-
@data.steps = StepCollection.new(context.data.steps.templates)
|
|
32
|
-
@data.notify = []
|
|
33
|
-
@data.env = {}
|
|
34
|
-
|
|
35
|
-
# Use `clone` to copy over dsl's extended extensions
|
|
36
|
-
@dsl = context.dsl.clone
|
|
37
|
-
# Override dsl context to current pipeline
|
|
38
|
-
@dsl.instance_variable_set(:@context, self)
|
|
39
|
-
|
|
40
|
-
instance_eval(&block) if block_given?
|
|
41
|
-
self
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def to_h
|
|
45
|
-
# Merge envs from main pipeline, since ruby does not have `reverse_merge` and
|
|
46
|
-
# `data` does not allow keys override, we have to reset the data hash per key.
|
|
47
|
-
@context.data.env.merge(data.env).each do |key, value|
|
|
48
|
-
data.env[key] = value
|
|
49
|
-
end
|
|
50
|
-
data.to_definition
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def method_missing(method_name, *args, **kwargs, &_block)
|
|
54
|
-
@dsl.public_send(method_name, *args, **kwargs, &_block)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def pipeline_yml
|
|
58
|
-
@pipeline_yml ||= "tmp/buildkite-builder/#{SecureRandom.urlsafe_base64}.yml"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def prepare
|
|
63
|
-
context.data.pipelines = PipelineCollection.new(context.artifacts)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
dsl do
|
|
67
|
-
def pipeline(name, &block)
|
|
68
|
-
raise "Subpipeline must have a name" if name.empty?
|
|
69
|
-
raise "Subpipeline does not allow nested in another Subpipeline" if context.is_a?(Buildkite::Builder::Extensions::SubPipelines::Pipeline)
|
|
70
|
-
|
|
71
|
-
sub_pipeline = Buildkite::Builder::Extensions::SubPipelines::Pipeline.new(name, context, &block)
|
|
72
|
-
context.data.pipelines.add(sub_pipeline)
|
|
73
|
-
|
|
74
|
-
trigger_step = context.data.steps.add(Pipelines::Steps::Trigger)
|
|
75
|
-
trigger_step.trigger(name)
|
|
76
|
-
|
|
77
|
-
build_options = {
|
|
78
|
-
message: '${BUILDKITE_MESSAGE}',
|
|
79
|
-
commit: '${BUILDKITE_COMMIT}',
|
|
80
|
-
branch: '${BUILDKITE_BRANCH}',
|
|
81
|
-
env: {
|
|
82
|
-
BUILDKITE_PULL_REQUEST: '${BUILDKITE_PULL_REQUEST}',
|
|
83
|
-
BUILDKITE_PULL_REQUEST_BASE_BRANCH: '${BUILDKITE_PULL_REQUEST_BASE_BRANCH}',
|
|
84
|
-
BUILDKITE_PULL_REQUEST_REPO: '${BUILDKITE_PULL_REQUEST_REPO}',
|
|
85
|
-
BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
build_options.merge!(sub_pipeline.build) if sub_pipeline.build
|
|
89
|
-
|
|
90
|
-
trigger_step.build(build_options)
|
|
91
|
-
trigger_step.key(sub_pipeline.key || "subpipeline_#{name}_#{context.data.pipelines.count}")
|
|
92
|
-
trigger_step.label(sub_pipeline.label || name.capitalize)
|
|
93
|
-
trigger_step.async(sub_pipeline.async || false)
|
|
94
|
-
trigger_step.branches(sub_pipeline.branches) if sub_pipeline.branches
|
|
95
|
-
trigger_step.condition(sub_pipeline.condition) if sub_pipeline.condition
|
|
96
|
-
trigger_step.depends_on(*sub_pipeline.get('depends_on')) if sub_pipeline.get('depends_on')
|
|
97
|
-
trigger_step.allow_dependency_failure(sub_pipeline.allow_dependency_failure || false)
|
|
98
|
-
trigger_step.skip(sub_pipeline.skip || false)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module Buildkite
|
|
2
|
-
module Builder
|
|
3
|
-
class Group
|
|
4
|
-
include Buildkite::Pipelines::Attributes
|
|
5
|
-
|
|
6
|
-
attr_reader :label
|
|
7
|
-
attr_reader :data
|
|
8
|
-
|
|
9
|
-
attribute :depends_on, append: true
|
|
10
|
-
attribute :key
|
|
11
|
-
|
|
12
|
-
def self.to_sym
|
|
13
|
-
name.split('::').last.downcase.to_sym
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def initialize(label, context, &block)
|
|
17
|
-
@label = label
|
|
18
|
-
@data = Data.new
|
|
19
|
-
@data.steps = StepCollection.new(context.data.steps.templates)
|
|
20
|
-
@data.notify = []
|
|
21
|
-
|
|
22
|
-
# Use `clone` to copy over dsl's extended extensions
|
|
23
|
-
@dsl = context.dsl.clone
|
|
24
|
-
# Override dsl context to current group
|
|
25
|
-
@dsl.instance_variable_set(:@context, self)
|
|
26
|
-
|
|
27
|
-
instance_eval(&block) if block_given?
|
|
28
|
-
self
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def to_h
|
|
32
|
-
attributes = super
|
|
33
|
-
{ group: label }.merge(attributes).merge(data.to_definition)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def method_missing(method_name, *args, **kwargs, &_block)
|
|
37
|
-
@dsl.public_send(method_name, *args, **kwargs, &_block)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require "forwardable"
|
|
2
|
-
|
|
3
|
-
module Buildkite
|
|
4
|
-
module Builder
|
|
5
|
-
class PipelineCollection
|
|
6
|
-
extend Forwardable
|
|
7
|
-
|
|
8
|
-
attr_reader :pipelines
|
|
9
|
-
|
|
10
|
-
def_delegator :@pipelines, :count
|
|
11
|
-
def_delegator :@pipelines, :each
|
|
12
|
-
|
|
13
|
-
def initialize(artifacts)
|
|
14
|
-
@artifacts = artifacts
|
|
15
|
-
@pipelines = []
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def add(pipeline)
|
|
19
|
-
unless pipeline.is_a?(Buildkite::Builder::Extensions::SubPipelines::Pipeline)
|
|
20
|
-
raise "`#{pipeline}` must be a Buildkite::Builder::Extensions::SubPipelines::Pipeline"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
pipelines << pipeline
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_definition
|
|
27
|
-
# Instead of generates pipeline.yml, subpipelines save generated file to artifacts
|
|
28
|
-
pipelines.each do |pipeline|
|
|
29
|
-
file = Pathname.new(pipeline.pipeline_yml)
|
|
30
|
-
file.dirname.mkpath
|
|
31
|
-
file.write(YAML.dump(Pipelines::Helpers.sanitize(pipeline.to_h)))
|
|
32
|
-
|
|
33
|
-
@artifacts << file
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
nil
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Buildkite
|
|
4
|
-
module Pipelines
|
|
5
|
-
module Steps
|
|
6
|
-
class Skip < Abstract
|
|
7
|
-
# This skip step is not an official Buildkite step. A skip step is really
|
|
8
|
-
# just a command step that does nothing and is used to portray a hidden
|
|
9
|
-
# step on the Buildkite web UI.
|
|
10
|
-
#
|
|
11
|
-
# Since it is it's own class, pipeline processors will be able to distinguish
|
|
12
|
-
# between this type of skip and a conditional skip. Conditional skips are
|
|
13
|
-
# full command or trigger steps skipped by the `skip` attribute. They can be
|
|
14
|
-
# unskipped in processors for certain situations. See the `DefaultBranch`
|
|
15
|
-
# processor for example.
|
|
16
|
-
|
|
17
|
-
# Do NOT sort this list. The order here is carried over to the YAML output.
|
|
18
|
-
# The order specified here was deliberate.
|
|
19
|
-
attribute :label
|
|
20
|
-
attribute :skip
|
|
21
|
-
attribute :if, as: :condition
|
|
22
|
-
attribute :depends_on, append: true
|
|
23
|
-
attribute :allow_dependency_failure
|
|
24
|
-
attribute :command
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|