buildkite-builder 2.0.0.beta2 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 671edc2f2b7a65af8d8c8d1390485c9591fb4814c1f9d1acb49e82fd3d648c27
4
- data.tar.gz: 78f6374f0b352172d61185ed5bb9c9054dbf20581001d634d5474ffdaf13afdb
3
+ metadata.gz: 1796ef4fc73c74c399a7eb271092baee5b0101e3c06598c8d837d1fd031876e2
4
+ data.tar.gz: c384d20a194cf13a8dff4e1057a1b07b777201fd717f1d75496d88ec04d7fbff
5
5
  SHA512:
6
- metadata.gz: 8be88ac275466dc0dec40db8ce78f752b488b568ed7b32403977e53905fc4fd8518298716cb1864a5bb9ab6a51ea3ed3572051a839f215c76cf7b6e6efdbf218
7
- data.tar.gz: 013a0a8e0ea3a56671088a1ec32994d456e83f49fd64b1b8d802b4fce53f54048581d10f21db56d213a8f9057797f494627b14e7390df83bc0b19ee6aceefb19
6
+ metadata.gz: cc19aa8d8c3af6f4fbbd0bd892d56f41243649b8b384e38f7391d8e198950704bc515530c022c231eb7d4368a7bed0f74fa0f4bab3c020813bf045b67a4d1062
7
+ data.tar.gz: e414869940fbb417e06192a7fdd48049d38564c00f1283a8110c2521462ce736ec890c7275c03c386b619ae718b654a4ac2cbbf460cb1f1dfd86cefb4e871b2c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 2.1.0
2
+ * Fix a bug introduced in 2.0.0 where artifacts were being uploaded before extensions had a chance to do work.
3
+ * Remove `SortedSet` dependency.
4
+ * Add `annotate` pipeline command helper.
5
+ * Add `StepCollection#find` and `StepCollection#find!` for ease of finding a step by its key in extensions.
6
+ * `group` now supports the `emoji:` helper. (Eg. `group "foobar", emoji: :smile`)
7
+
8
+ ## 2.0.0
9
+ * Add support for `group`.
10
+ * `Processor`s has been renamed to `Extension`. Extensions add more capabilities (will document separately).
11
+ * `plugin` no longer takes 2 arguments (source, version). It's simply 1 arg that is both source and version, separated by a `#`. This is more akin to Buildkite's usage.
12
+ * Full refactor of pipeline code allowing for extensions to extend DSL methods.
13
+
1
14
  ## 1.5.0
2
15
  * Merge `BuildKite::Builder::Context` and `BuildKite::Pipelines::Pipeline` to `BuildKite::Builder::Pipeline` (#37)
3
16
 
data/README.md CHANGED
@@ -28,7 +28,7 @@ steps:
28
28
  - label: ":toolbox:"
29
29
  plugins:
30
30
  - docker#v3.7.0:
31
- image: gusto/buildkite-builder:1.2.0
31
+ image: gusto/buildkite-builder:2.1.0
32
32
  propagate-environment: true
33
33
  ```
34
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta2
1
+ 2.1.0
@@ -4,20 +4,25 @@ 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
 
12
12
  dsl do
13
- def group(label = nil, &block)
13
+ def group(label = nil, emoji: nil, &block)
14
14
  raise "Group does not allow nested in another Group" if context.is_a?(Group)
15
15
 
16
+ if emoji
17
+ emoji = Array(emoji).map { |name| ":#{name}:" }.join
18
+ label = [emoji, label].compact.join(' ')
19
+ end
20
+
16
21
  context.data.steps.push(Buildkite::Builder::Group.new(label, context.data.steps, &block))
17
22
  end
18
23
 
19
- def plugin(name, uri, version)
20
- context.data.steps.plugins.add(name, uri, version)
24
+ def plugin(name, uri)
25
+ context.data.steps.plugins.add(name, uri)
21
26
  end
22
27
 
23
28
  def block(template = nil, **args, &block)
@@ -20,7 +20,7 @@ module Buildkite
20
20
  end
21
21
 
22
22
  def initialize
23
- @modified_files = SortedSet.new(pull_request? ? files_from_pull_request : files_from_git)
23
+ @modified_files = Set.new(pull_request? ? files_from_pull_request.sort! : files_from_git.sort!)
24
24
  end
25
25
 
26
26
  private
@@ -36,7 +36,7 @@ module Buildkite
36
36
  matched.map! { |file| Pathname.new(file) }
37
37
  matched.reject!(&:directory?)
38
38
  matched.map! { |file| file.relative_path_from(Builder.root) }
39
- SortedSet.new(matched)
39
+ Set.new(matched.sort!)
40
40
  end
41
41
  end
42
42
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'digest/md5'
4
4
  require 'pathname'
5
- require 'sorted_set'
6
5
 
7
6
  module Buildkite
8
7
  module Builder
@@ -56,7 +55,7 @@ module Buildkite
56
55
  end
57
56
 
58
57
  def files
59
- @files ||= inclusion_rules.map(&:files).reduce(SortedSet.new, :merge) - exclusion_rules.map(&:files).reduce(SortedSet.new, :merge)
58
+ @files ||= (inclusion_rules.map(&:files).reduce(Set.new, :merge) - exclusion_rules.map(&:files).reduce(Set.new, :merge)).sort.to_set
60
59
  end
61
60
 
62
61
  def digest
@@ -40,9 +40,6 @@ module Buildkite
40
40
  end
41
41
 
42
42
  def upload
43
- logger.info '+++ :paperclip: Uploading artifacts'
44
- upload_artifacts
45
-
46
43
  # Upload the pipeline.
47
44
  Tempfile.create(['pipeline', '.yml']) do |file|
48
45
  file.sync = true
@@ -53,6 +50,9 @@ module Buildkite
53
50
  logger.info '+++ :pipeline: Uploading pipeline'
54
51
  Buildkite::Pipelines::Command.pipeline!(:upload, file.path)
55
52
  end
53
+
54
+ logger.info '+++ :paperclip: Uploading artifacts'
55
+ upload_artifacts
56
56
  end
57
57
 
58
58
  def to_h
@@ -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)
@@ -27,6 +27,14 @@ module Buildkite
27
27
  end
28
28
  end
29
29
 
30
+ def find(key)
31
+ @steps.find { |step| step.has?(:key) && step.key == key.to_s }
32
+ end
33
+
34
+ def find!(key)
35
+ find(key) || raise(ArgumentError, "Can't find step with key: #{key}")
36
+ end
37
+
30
38
  def add(step_class, template = nil, **args, &block)
31
39
  @steps.push(step_class.new(self, template, **args, &block)).last
32
40
  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
 
@@ -21,6 +21,14 @@ module Buildkite
21
21
  new(:artifact, subcommand, *args).run
22
22
  end
23
23
 
24
+ def self.annotate(body, *args)
25
+ new(:annotate, body, *args).run
26
+ end
27
+
28
+ def self.annotate!(*args)
29
+ abort unless annotate(*args)
30
+ end
31
+
24
32
  def initialize(command, subcommand, *args)
25
33
  @command = command.to_s
26
34
  @subcommand = subcommand.to_s
@@ -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.beta2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
@@ -9,22 +9,8 @@ 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-27 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: sorted_set
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: rainbow
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -155,10 +141,12 @@ files:
155
141
  - lib/buildkite/builder/manifest.rb
156
142
  - lib/buildkite/builder/manifest/rule.rb
157
143
  - lib/buildkite/builder/pipeline.rb
158
- - lib/buildkite/builder/plugin_registry.rb
144
+ - lib/buildkite/builder/plugin.rb
145
+ - lib/buildkite/builder/plugin_collection.rb
146
+ - lib/buildkite/builder/plugin_manager.rb
159
147
  - lib/buildkite/builder/rainbow.rb
160
148
  - lib/buildkite/builder/step_collection.rb
161
- - lib/buildkite/builder/template_registry.rb
149
+ - lib/buildkite/builder/template_manager.rb
162
150
  - lib/buildkite/env.rb
163
151
  - lib/buildkite/pipelines.rb
164
152
  - lib/buildkite/pipelines/api.rb
@@ -175,7 +163,6 @@ files:
175
163
  - lib/buildkite/pipelines/helpers/skip.rb
176
164
  - lib/buildkite/pipelines/helpers/soft_fail.rb
177
165
  - lib/buildkite/pipelines/helpers/timeout_in_minutes.rb
178
- - lib/buildkite/pipelines/plugin.rb
179
166
  - lib/buildkite/pipelines/step_context.rb
180
167
  - lib/buildkite/pipelines/steps.rb
181
168
  - lib/buildkite/pipelines/steps/abstract.rb
@@ -204,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
191
  version: 2.3.0
205
192
  required_rubygems_version: !ruby/object:Gem::Requirement
206
193
  requirements:
207
- - - ">"
194
+ - - ">="
208
195
  - !ruby/object:Gem::Version
209
- version: 1.3.1
196
+ version: '0'
210
197
  requirements: []
211
198
  rubygems_version: 3.2.2
212
199
  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