buildkite-builder 3.8.3 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2591489e3b57711b38926cf558ee362c2c579086b46ff800fccffb8db4598a92
4
- data.tar.gz: cc12ee969c8e846008f13eea3ad61de0efa32d8706bda83ce76a3bf7e8b7772f
3
+ metadata.gz: 38dd50aa0554deb37552ff778d49fd94bd4e22e242ae72ccf179fdcf3460cf25
4
+ data.tar.gz: a134a4f33462478c35b965c4dbbdb4451cfd4b383817150fc192301fada635af
5
5
  SHA512:
6
- metadata.gz: 6901d0afda1b70080615f5937ef7fa17c90023f1141606e4adf8f77b5ac3252da2f656070b22528b8eea2703686fb2e7af30575f6075e2d19e730a4b4c0df9e5
7
- data.tar.gz: 39d6c40ec9a8f194997af75eb4776753d3b6904bbd19783e1592f92b260f918ccbda81c764efca332305e1f67073bcf7f060d52931a8738c1a2a7a56ffa5a924
6
+ metadata.gz: '02599590709a1ca3f7e19da232889b3bf26ff316ff48dc10b8ec3751efc1e08c39a3bf05c6eee21bc2d6463b296d8d777d1d89f5b55abd6ad1667ec89925fa8f'
7
+ data.tar.gz: a8b4e2b45030b631e1bbb9da80954a7debc9d056945e1e57f36b1df51e88fa68812bb3c99e3826536df356a0520d3e0fe830aa98fd7bea7f88a02dece853253e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.8.3
1
+ 3.9.0
@@ -0,0 +1,47 @@
1
+ module Buildkite
2
+ module Builder
3
+ module Extensions
4
+ class Plugins < Extension
5
+ attr_reader :manager
6
+
7
+ dsl do
8
+ def plugin(name, uri, default_attributes = {})
9
+ context.extensions.find(Buildkite::Builder::Extensions::Plugins).manager.add(name, uri, default_attributes)
10
+ end
11
+ end
12
+
13
+ def prepare
14
+ @manager = PluginManager.new
15
+ end
16
+
17
+ def build
18
+ context.data.steps.each(:command) do |step|
19
+ next unless step.has?(:plugins)
20
+
21
+ step.get(:plugins).map! do |plugin|
22
+ resource, attributes = extract_resource_and_attributes(plugin)
23
+ resource.is_a?(Symbol) ? manager.build(resource, attributes) : plugin
24
+ end
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
+ end
38
+
39
+ private
40
+
41
+ def extract_resource_and_attributes(plugin)
42
+ [plugin.keys.first, plugin.values.first]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -3,10 +3,7 @@ module Buildkite
3
3
  module Extensions
4
4
  class Steps < Extension
5
5
  def prepare
6
- context.data.steps = StepCollection.new(
7
- TemplateManager.new(context.root),
8
- PluginManager.new
9
- )
6
+ context.data.steps = StepCollection.new(TemplateManager.new(context.root))
10
7
  end
11
8
 
12
9
  dsl do
@@ -21,10 +18,6 @@ module Buildkite
21
18
  context.data.steps.push(Buildkite::Builder::Group.new(label, context, &block))
22
19
  end
23
20
 
24
- def plugin(name, uri, default_attributes = {})
25
- context.data.steps.plugins.add(name, uri, default_attributes)
26
- end
27
-
28
21
  def block(template = nil, **args, &block)
29
22
  context.data.steps.add(Pipelines::Steps::Block, template, **args, &block)
30
23
  end
@@ -28,10 +28,7 @@ module Buildkite
28
28
  @context = context
29
29
  @name = name
30
30
  @data = Data.new
31
- @data.steps = StepCollection.new(
32
- context.data.steps.templates,
33
- context.data.steps.plugins
34
- )
31
+ @data.steps = StepCollection.new(context.data.steps.templates)
35
32
  @data.notify = []
36
33
  @data.env = {}
37
34
 
@@ -8,6 +8,7 @@ module Buildkite
8
8
  autoload :Notify, File.expand_path('extensions/notify', __dir__)
9
9
  autoload :SubPipelines, File.expand_path('extensions/sub_pipelines', __dir__)
10
10
  autoload :Steps, File.expand_path('extensions/steps', __dir__)
11
+ autoload :Plugins, File.expand_path('extensions/plugins', __dir__)
11
12
  autoload :Use, File.expand_path('extensions/use', __dir__)
12
13
  end
13
14
  end
@@ -16,10 +16,7 @@ module Buildkite
16
16
  def initialize(label, context, &block)
17
17
  @label = label
18
18
  @data = Data.new
19
- @data.steps = StepCollection.new(
20
- context.data.steps.templates,
21
- context.data.steps.plugins
22
- )
19
+ @data.steps = StepCollection.new(context.data.steps.templates)
23
20
  @data.notify = []
24
21
 
25
22
  # Use `clone` to copy over dsl's extended extensions
@@ -38,6 +38,7 @@ module Buildkite
38
38
  use(Extensions::Env)
39
39
  use(Extensions::Notify)
40
40
  use(Extensions::Steps)
41
+ use(Extensions::Plugins)
41
42
  use(Extensions::SubPipelines)
42
43
  end
43
44
 
@@ -3,16 +3,16 @@
3
3
  module Buildkite
4
4
  module Builder
5
5
  class Plugin
6
- attr_reader :uri, :source, :version, :attributes
6
+ attr_reader \
7
+ :uri,
8
+ :source,
9
+ :version,
10
+ :default_attributes
7
11
 
8
- def initialize(uri, attributes = {})
12
+ def initialize(uri, default_attributes = {})
9
13
  @uri = uri
10
14
  @source, @version = uri.split('#')
11
- @attributes = attributes
12
- end
13
-
14
- def to_h
15
- Buildkite::Pipelines::Helpers.sanitize(uri => (attributes&.empty? ? nil : attributes))
15
+ @default_attributes = default_attributes
16
16
  end
17
17
  end
18
18
  end
@@ -7,23 +7,16 @@ module Buildkite
7
7
 
8
8
  def add(name, uri, default_attributes = {})
9
9
  name = name.to_s
10
+ raise(ArgumentError, "Plugin already defined: #{name}") if @plugins.key?(name)
10
11
 
11
- if @plugins.key?(name)
12
- raise ArgumentError, "Plugin already defined: #{name}"
13
- end
14
-
15
- @plugins[name] = {
16
- uri: uri,
17
- default_attributes: default_attributes
18
- }
12
+ @plugins[name] = Plugin.new(uri, default_attributes)
19
13
  end
20
14
 
21
- def fetch(name)
22
- @plugins[name]
23
- end
15
+ def build(name, attributes = {})
16
+ plugin = @plugins[name.to_s]
17
+ raise(ArgumentError, "Plugin is not registered: #{resource}") unless plugin
24
18
 
25
- def to_definition
26
- # No-op
19
+ { plugin.uri => plugin.default_attributes.merge(attributes) }
27
20
  end
28
21
  end
29
22
  end
@@ -2,12 +2,10 @@ module Buildkite
2
2
  module Builder
3
3
  class StepCollection
4
4
  attr_reader :templates
5
- attr_reader :plugins
6
5
  attr_reader :steps
7
6
 
8
- def initialize(templates, plugins)
7
+ def initialize(templates)
9
8
  @templates = templates
10
- @plugins = plugins
11
9
  @steps = []
12
10
  end
13
11
 
@@ -18,7 +18,6 @@ module Buildkite
18
18
  autoload :Processors, File.expand_path('builder/processors', __dir__)
19
19
  autoload :Rainbow, File.expand_path('builder/rainbow', __dir__)
20
20
  autoload :Plugin, File.expand_path('builder/plugin', __dir__)
21
- autoload :PluginCollection, File.expand_path('builder/plugin_collection', __dir__)
22
21
  autoload :StepCollection, File.expand_path('builder/step_collection', __dir__)
23
22
  autoload :PipelineCollection, File.expand_path('builder/pipeline_collection', __dir__)
24
23
  autoload :TemplateManager, File.expand_path('builder/template_manager', __dir__)
@@ -5,12 +5,7 @@ module Buildkite
5
5
  module Helpers
6
6
  module Plugins
7
7
  def plugin(name_or_source, plugin_attributes = {})
8
- attributes['plugins'] ||= Buildkite::Builder::PluginCollection.new(step_collection.plugins)
9
- attributes['plugins'].add(name_or_source, plugin_attributes)
10
- end
11
-
12
- def plugins
13
- attributes['plugins']
8
+ append(:plugins, { name_or_source => plugin_attributes })
14
9
  end
15
10
  end
16
11
  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: 3.8.3
4
+ version: 3.9.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-09 00:00:00.000000000 Z
12
+ date: 2022-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -113,6 +113,7 @@ files:
113
113
  - lib/buildkite/builder/extensions/env.rb
114
114
  - lib/buildkite/builder/extensions/lib.rb
115
115
  - lib/buildkite/builder/extensions/notify.rb
116
+ - lib/buildkite/builder/extensions/plugins.rb
116
117
  - lib/buildkite/builder/extensions/steps.rb
117
118
  - lib/buildkite/builder/extensions/sub_pipelines.rb
118
119
  - lib/buildkite/builder/extensions/use.rb
@@ -125,7 +126,6 @@ files:
125
126
  - lib/buildkite/builder/pipeline.rb
126
127
  - lib/buildkite/builder/pipeline_collection.rb
127
128
  - lib/buildkite/builder/plugin.rb
128
- - lib/buildkite/builder/plugin_collection.rb
129
129
  - lib/buildkite/builder/plugin_manager.rb
130
130
  - lib/buildkite/builder/rainbow.rb
131
131
  - lib/buildkite/builder/step_collection.rb
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.3.7
180
+ rubygems_version: 3.3.26
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: A gem for programmatically creating Buildkite pipelines.
@@ -1,49 +0,0 @@
1
- module Buildkite
2
- module Builder
3
- class PluginCollection
4
- attr_reader :plugin_manager
5
-
6
- def initialize(plugin_manager)
7
- @plugin_manager = plugin_manager
8
- @collection = []
9
- end
10
-
11
- def add(resource, attributes = {})
12
- plugin =
13
- case resource
14
- when Symbol
15
- registered_plugin = plugin_manager.fetch(resource.to_s)
16
-
17
- raise ArgumentError, "Plugin `#{resource}` does not exist" unless registered_plugin
18
-
19
- Plugin.new(registered_plugin[:uri], registered_plugin[:default_attributes].merge(attributes))
20
- when String
21
- Plugin.new(resource, attributes)
22
- when Plugin
23
- resource
24
- else
25
- raise ArgumentError, "Unknown plugin `#{resource.inspect}`"
26
- end
27
-
28
- @collection.push(plugin).last
29
- end
30
-
31
- def find(source)
32
- source_string =
33
- case source
34
- when String then source
35
- when Plugin then source.source
36
- else raise ArgumentError, "Unknown source #{source.inspect}"
37
- end
38
-
39
- @collection.select do |plugin|
40
- plugin.source == source_string
41
- end
42
- end
43
-
44
- def to_definition
45
- @collection.map(&:to_h)
46
- end
47
- end
48
- end
49
- end