buildkite-builder 2.0.0.beta2 → 2.0.0.beta3

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: 671edc2f2b7a65af8d8c8d1390485c9591fb4814c1f9d1acb49e82fd3d648c27
4
- data.tar.gz: 78f6374f0b352172d61185ed5bb9c9054dbf20581001d634d5474ffdaf13afdb
3
+ metadata.gz: a4927ec61e94b42ab3c54f0cdafa0c9773b24876e9f5fd067eed495269db3e08
4
+ data.tar.gz: c730432ae672df3893b03e1ee0a6097f0f525c2f5236df642159ae93882cdbbc
5
5
  SHA512:
6
- metadata.gz: 8be88ac275466dc0dec40db8ce78f752b488b568ed7b32403977e53905fc4fd8518298716cb1864a5bb9ab6a51ea3ed3572051a839f215c76cf7b6e6efdbf218
7
- data.tar.gz: 013a0a8e0ea3a56671088a1ec32994d456e83f49fd64b1b8d802b4fce53f54048581d10f21db56d213a8f9057797f494627b14e7390df83bc0b19ee6aceefb19
6
+ metadata.gz: 92fe3fea6d81dabd5da1eacb55445e54845ba6d53c6b059f17e665de6e794341367cdedcad6d89d14cd47a229e8503bf59120bbb6e0ccad40c2e49fa49f51589
7
+ data.tar.gz: fb4b849e2987e39c6bef52c3896822900151e1c8f12a00b4e825e405348bba62c3dc91275ecc93ae2ac892a96efbcb1d7b12a5962723e8b84664d96249908630
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta2
1
+ 2.0.0.beta3
@@ -4,8 +4,8 @@ module Buildkite
4
4
  class Steps < Extension
5
5
  def prepare
6
6
  context.data.steps = StepCollection.new(
7
- TemplateRegistry.new(context.root),
8
- PluginRegistry.new
7
+ TemplateManager.new(context.root),
8
+ PluginManager.new
9
9
  )
10
10
  end
11
11
 
@@ -16,8 +16,8 @@ module Buildkite
16
16
  context.data.steps.push(Buildkite::Builder::Group.new(label, context.data.steps, &block))
17
17
  end
18
18
 
19
- def plugin(name, uri, version)
20
- context.data.steps.plugins.add(name, uri, version)
19
+ def plugin(name, uri)
20
+ context.data.steps.plugins.add(name, uri)
21
21
  end
22
22
 
23
23
  def block(template = nil, **args, &block)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buildkite
4
+ module Builder
5
+ class Plugin
6
+ attr_reader :uri, :source, :version, :options
7
+
8
+ def initialize(uri, options = nil)
9
+ @uri = uri
10
+ @source, @version = uri.split('#')
11
+ @options = options
12
+ end
13
+
14
+ def to_h
15
+ Buildkite::Pipelines::Helpers.sanitize(uri => options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
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, options = nil)
12
+ plugin =
13
+ case resource
14
+ when Symbol
15
+ uri = plugin_manager.fetch(resource.to_s)
16
+
17
+ raise ArgumentError, "Plugin `#{resource}` does not exist" unless uri
18
+
19
+ Plugin.new(uri, options)
20
+ when String
21
+ Plugin.new(resource, options)
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.inpect}"
37
+ end
38
+
39
+ @collection.select do |plugin|
40
+ plugin.source == source_string
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,18 +1,18 @@
1
1
  module Buildkite
2
2
  module Builder
3
- class PluginRegistry
3
+ class PluginManager
4
4
  def initialize
5
5
  @plugins = {}
6
6
  end
7
7
 
8
- def add(name, uri, version)
8
+ def add(name, uri)
9
9
  name = name.to_s
10
10
 
11
11
  if @plugins.key?(name)
12
12
  raise ArgumentError, "Plugin already defined: #{name}"
13
13
  end
14
14
 
15
- @plugins[name] = [uri, version]
15
+ @plugins[name] = uri
16
16
  end
17
17
 
18
18
  def fetch(name)
@@ -1,6 +1,6 @@
1
1
  module Buildkite
2
2
  module Builder
3
- class TemplateRegistry
3
+ class TemplateManager
4
4
  def initialize(root)
5
5
  @templates = {}
6
6
 
@@ -20,9 +20,11 @@ module Buildkite
20
20
  autoload :Manifest, File.expand_path('builder/manifest', __dir__)
21
21
  autoload :Processors, File.expand_path('builder/processors', __dir__)
22
22
  autoload :Rainbow, File.expand_path('builder/rainbow', __dir__)
23
+ autoload :Plugin, File.expand_path('builder/plugin', __dir__)
24
+ autoload :PluginCollection, File.expand_path('builder/plugin_collection', __dir__)
23
25
  autoload :StepCollection, File.expand_path('builder/step_collection', __dir__)
24
- autoload :TemplateRegistry, File.expand_path('builder/template_registry', __dir__)
25
- autoload :PluginRegistry, File.expand_path('builder/plugin_registry', __dir__)
26
+ autoload :TemplateManager, File.expand_path('builder/template_manager', __dir__)
27
+ autoload :PluginManager, File.expand_path('builder/plugin_manager', __dir__)
26
28
 
27
29
  BUILDKITE_DIRECTORY_NAME = Pathname.new('.buildkite').freeze
28
30
 
@@ -4,19 +4,18 @@ module Buildkite
4
4
  module Pipelines
5
5
  module Helpers
6
6
  module Plugins
7
- def plugin(plugin_name, options = nil)
8
- plugin_name = plugin_name.to_s
9
- @plugins ||= {}
7
+ def plugin(name_or_source, options = nil)
8
+ append(:plugins, plugin_collection.add(name_or_source, options).to_h)
9
+ end
10
10
 
11
- if @plugins.key?(plugin_name)
12
- raise ArgumentError, "Plugin already used for command step: #{plugin_name}"
13
- end
11
+ def plugins
12
+ plugin_collection
13
+ end
14
14
 
15
- uri, version = step_collection.plugins.fetch(plugin_name)
16
- new_plugin = Plugin.new(uri, version, options)
17
- @plugins[plugin_name] = new_plugin
15
+ private
18
16
 
19
- plugins(new_plugin.to_h)
17
+ def plugin_collection
18
+ @plugin_collection ||= Buildkite::Builder::PluginCollection.new(step_collection.plugins)
20
19
  end
21
20
  end
22
21
  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: 2.0.0.beta2
4
+ version: 2.0.0.beta3
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: 2021-08-20 00:00:00.000000000 Z
12
+ date: 2021-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sorted_set
@@ -155,10 +155,12 @@ files:
155
155
  - lib/buildkite/builder/manifest.rb
156
156
  - lib/buildkite/builder/manifest/rule.rb
157
157
  - lib/buildkite/builder/pipeline.rb
158
- - lib/buildkite/builder/plugin_registry.rb
158
+ - lib/buildkite/builder/plugin.rb
159
+ - lib/buildkite/builder/plugin_collection.rb
160
+ - lib/buildkite/builder/plugin_manager.rb
159
161
  - lib/buildkite/builder/rainbow.rb
160
162
  - lib/buildkite/builder/step_collection.rb
161
- - lib/buildkite/builder/template_registry.rb
163
+ - lib/buildkite/builder/template_manager.rb
162
164
  - lib/buildkite/env.rb
163
165
  - lib/buildkite/pipelines.rb
164
166
  - lib/buildkite/pipelines/api.rb
@@ -175,7 +177,6 @@ files:
175
177
  - lib/buildkite/pipelines/helpers/skip.rb
176
178
  - lib/buildkite/pipelines/helpers/soft_fail.rb
177
179
  - lib/buildkite/pipelines/helpers/timeout_in_minutes.rb
178
- - lib/buildkite/pipelines/plugin.rb
179
180
  - lib/buildkite/pipelines/step_context.rb
180
181
  - lib/buildkite/pipelines/steps.rb
181
182
  - lib/buildkite/pipelines/steps/abstract.rb
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Buildkite
4
- module Pipelines
5
- class Plugin
6
- attr_reader :uri, :version, :options
7
-
8
- def initialize(uri, version, options = nil)
9
- @uri = uri
10
- @version = version
11
- @options = options
12
- end
13
-
14
- def full_uri
15
- "#{uri}##{version}"
16
- end
17
-
18
- def to_h
19
- Helpers.sanitize(full_uri => options)
20
- end
21
- end
22
- end
23
- end