buildkite-builder 2.0.0.beta1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a9777c2d258caf0ee500fee89d04fe9385a9357f2df66f007b60c88bd361afa
4
- data.tar.gz: f8a8e77e07fe770231f00bc7d3a693524cb5495f45c0529313737152dd44be1f
3
+ metadata.gz: 827239e1a697a723a13cf14a5793bf17490d102611003270b3ef73e196428f5c
4
+ data.tar.gz: dfe7bf3a2f6e63916812a28b93af9f8b25979fafa8f1b35a608819e4cc4a94bc
5
5
  SHA512:
6
- metadata.gz: 824bb77591ec310cace0138dd32269cd379ba244ec0283b53cd86d1e6001b24bd0a208c5662bf1b4d171c773e85c0053decfe619431cccbe6c38e24e7badb32d
7
- data.tar.gz: 30502c1de926f6e48423b4d254dc82b86248f2bf5c7e290f50bd972b63ef9d9702bbdd0dd4c81f3cd37aa0da5b3f4076402d72d3f6eb5531b662a96cfdbfa3a4
6
+ metadata.gz: 3e64effb01732d99febf7516897c95d0dd45ca5a4c5dbf61da73dcb0843a3459c6a5ff3ba1e74861f9ab4029a312cfe6225de2a7dc0968c50952d4473920d5e2
7
+ data.tar.gz: 3d95fbab003838087d12626fd7240ba7f6359434af0c8e87af15fce0804bcafa219f4af049f6b81e2dbc786eca0152daa8801b41210539e693c0afd2e5607043
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta1
1
+ 2.0.0
@@ -9,7 +9,7 @@ module Buildkite
9
9
  self.description = 'Outputs the pipeline YAML.'
10
10
 
11
11
  def run
12
- puts Pipeline.build(pipeline_path).to_yaml
12
+ puts Pipeline.new(pipeline_path).to_yaml
13
13
  end
14
14
  end
15
15
  end
@@ -6,7 +6,11 @@ module Buildkite
6
6
  attr_reader :context
7
7
 
8
8
  def extend(mod)
9
- mod < Extension ? super(mod.dsl) : super
9
+ if mod < Extension
10
+ super(mod.dsl) if mod.dsl
11
+ else
12
+ super
13
+ end
10
14
  end
11
15
 
12
16
  def initialize(context)
@@ -28,6 +28,10 @@ module Buildkite
28
28
 
29
29
  private
30
30
 
31
+ def log
32
+ context.logger
33
+ end
34
+
31
35
  def buildkite
32
36
  @buildkite ||= begin
33
37
  unless Buildkite.env
@@ -43,8 +47,7 @@ module Buildkite
43
47
  end
44
48
 
45
49
  def pipeline(&block)
46
- context.dsl.instance_eval(&block) if block_given?
47
- context
50
+ context.dsl.instance_eval(&block)
48
51
  end
49
52
  end
50
53
  end
@@ -8,10 +8,10 @@ module Buildkite
8
8
  @context = context
9
9
  @extensions = []
10
10
 
11
- Loaders::Extensions.load(@context.root)
11
+ @loader = Loaders::Extensions.load(@context.root)
12
12
  end
13
13
 
14
- def use(extension, **args)
14
+ def use(extension, native: false, **args)
15
15
  unless extension < Buildkite::Builder::Extension
16
16
  raise "#{extension} must subclass Buildkite::Builder::Extension"
17
17
  end
@@ -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)
@@ -25,7 +25,8 @@ module Buildkite
25
25
  @dsl = Dsl.new(self)
26
26
  @dsl.extend(Extensions::Steps)
27
27
  @dsl.extend(Extensions::Notify)
28
- instance_eval(&block)
28
+ instance_eval(&block) if block_given?
29
+ self
29
30
  end
30
31
 
31
32
  def to_h
@@ -33,8 +34,8 @@ module Buildkite
33
34
  { group: label }.merge(attributes).merge(data.to_definition)
34
35
  end
35
36
 
36
- def method_missing(method_name, *_args, &_block)
37
- @dsl.public_send(method_name, *_args, &_block)
37
+ def method_missing(method_name, *args, **kwargs, &_block)
38
+ @dsl.public_send(method_name, *args, **kwargs, &_block)
38
39
  end
39
40
  end
40
41
  end
@@ -23,10 +23,6 @@ module Buildkite
23
23
  :dsl,
24
24
  :data
25
25
 
26
- def self.build(root, logger: nil)
27
- new(root, logger: logger)
28
- end
29
-
30
26
  def initialize(root, logger: nil)
31
27
  @root = root
32
28
  @logger = logger || Logger.new(File::NULL)
@@ -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,49 @@
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.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
@@ -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)
@@ -17,12 +17,12 @@ module Buildkite
17
17
  @steps.each do |step|
18
18
  if types.include?(step.class.to_sym)
19
19
  yield step
20
- end
21
-
22
- if step.is_a?(Group)
20
+ elsif step.is_a?(Group)
23
21
  step.data.steps.each(*types) do |step|
24
22
  yield step
25
23
  end
24
+ elsif types.empty?
25
+ yield step
26
26
  end
27
27
  end
28
28
  end
@@ -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
 
@@ -48,7 +48,9 @@ module Buildkite
48
48
 
49
49
  def to_h
50
50
  permitted_attributes.each_with_object({}) do |attr, hash|
51
- hash[attr] = get(attr) if has?(attr)
51
+ next unless has?(attr)
52
+
53
+ hash[attr] = get(attr).respond_to?(:to_definition) ? get(attr).to_definition : get(attr)
52
54
  end
53
55
  end
54
56
 
@@ -4,19 +4,13 @@ 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 ||= {}
10
-
11
- if @plugins.key?(plugin_name)
12
- raise ArgumentError, "Plugin already used for command step: #{plugin_name}"
13
- end
14
-
15
- uri, version = step_collection.plugins.fetch(plugin_name)
16
- new_plugin = Plugin.new(uri, version, options)
17
- @plugins[plugin_name] = new_plugin
7
+ def plugin(name_or_source, options = nil)
8
+ attributes['plugins'] ||= Buildkite::Builder::PluginCollection.new(step_collection.plugins)
9
+ attributes['plugins'].add(name_or_source, options)
10
+ end
18
11
 
19
- plugins(new_plugin.to_h)
12
+ def plugins
13
+ attributes['plugins']
20
14
  end
21
15
  end
22
16
  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.beta1
4
+ version: 2.0.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: 2021-08-20 00:00:00.000000000 Z
12
+ date: 2021-08-25 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
@@ -204,9 +205,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
205
  version: 2.3.0
205
206
  required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  requirements:
207
- - - ">"
208
+ - - ">="
208
209
  - !ruby/object:Gem::Version
209
- version: 1.3.1
210
+ version: '0'
210
211
  requirements: []
211
212
  rubygems_version: 3.2.2
212
213
  signing_key:
@@ -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