buildkite-builder 3.8.2 → 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: 1e65dcfa8d56f8779fcea38cd8781936c81a345030b0d42beb8a9b3107df1d3d
4
- data.tar.gz: 89ba3c3f054d3147eb171a0adeae6b2e8f33386e1e07293177d1e6f1d8a9d305
3
+ metadata.gz: 38dd50aa0554deb37552ff778d49fd94bd4e22e242ae72ccf179fdcf3460cf25
4
+ data.tar.gz: a134a4f33462478c35b965c4dbbdb4451cfd4b383817150fc192301fada635af
5
5
  SHA512:
6
- metadata.gz: e255c6d59f6eeac2d7d98333302e4ad7b9bd9142441f9c8497c2cf81176dae920deba573d38a83dc5e4bcca15205689924afe38822ceb8e82c35ee429e9efc39
7
- data.tar.gz: 3122928b318900c555bbca30fca1e14bf0a0f5e559942eb1d8bbcac3f44830d3f9ed64e99b44add9d94e76aa0b834472d894b6398b414ea4da68e5f21631d412
6
+ metadata.gz: '02599590709a1ca3f7e19da232889b3bf26ff316ff48dc10b8ec3751efc1e08c39a3bf05c6eee21bc2d6463b296d8d777d1d89f5b55abd6ad1667ec89925fa8f'
7
+ data.tar.gz: a8b4e2b45030b631e1bbb9da80954a7debc9d056945e1e57f36b1df51e88fa68812bb3c99e3826536df356a0520d3e0fe830aa98fd7bea7f88a02dece853253e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.8.2
1
+ 3.9.0
@@ -15,7 +15,7 @@ module Buildkite
15
15
 
16
16
  # This entrypoint is for running on CI. It expects certain environment
17
17
  # variables to be set. It also uploads the pipeline to Buildkite.
18
- log.info "+++ 🧰 #{'Buildkite Builder'.color(:springgreen)} ─ #{relative_pipeline_path.to_s.yellow}"
18
+ log.info "+++ 🧰 #{'Buildkite Builder'.color(:springgreen)} v#{Buildkite::Builder.version} ─ #{relative_pipeline_path.to_s.yellow}"
19
19
 
20
20
  if Buildkite::Pipelines::Command.meta_data(:exists, Builder::META_DATA.fetch(:job))
21
21
  log.info 'Pipeline already uploaded'.color(:dimgray)
@@ -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
@@ -18,11 +15,7 @@ module Buildkite
18
15
  label = [emoji, label].compact.join(' ')
19
16
  end
20
17
 
21
- context.data.steps.push(Buildkite::Builder::Group.new(label, context.data.steps, &block))
22
- end
23
-
24
- def plugin(name, uri, default_attributes = {})
25
- context.data.steps.plugins.add(name, uri, default_attributes)
18
+ context.data.steps.push(Buildkite::Builder::Group.new(label, context, &block))
26
19
  end
27
20
 
28
21
  def block(template = nil, **args, &block)
@@ -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
@@ -13,18 +13,17 @@ module Buildkite
13
13
  name.split('::').last.downcase.to_sym
14
14
  end
15
15
 
16
- def initialize(label, steps, &block)
16
+ def initialize(label, context, &block)
17
17
  @label = label
18
18
  @data = Data.new
19
- @data.steps = StepCollection.new(
20
- steps.templates,
21
- steps.plugins
22
- )
19
+ @data.steps = StepCollection.new(context.data.steps.templates)
23
20
  @data.notify = []
24
21
 
25
- @dsl = Dsl.new(self)
26
- @dsl.extend(Extensions::Steps)
27
- @dsl.extend(Extensions::Notify)
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
+
28
27
  instance_eval(&block) if block_given?
29
28
  self
30
29
  end
@@ -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__)
@@ -35,6 +34,10 @@ module Buildkite
35
34
  @root ||= find_buildkite_directory(start_path)
36
35
  end
37
36
 
37
+ def version
38
+ @version ||= File.read(File.expand_path('../../VERSION', __dir__)).strip
39
+ end
40
+
38
41
  def template(&block)
39
42
  Definition::Template.new(&block) if block_given?
40
43
  end
@@ -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.2
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-11-23 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