buildkite-builder 1.0.0 → 1.4.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +118 -14
  4. data/VERSION +1 -1
  5. data/lib/buildkite/builder.rb +12 -15
  6. data/lib/buildkite/builder/commands/abstract.rb +49 -4
  7. data/lib/buildkite/builder/commands/files.rb +6 -7
  8. data/lib/buildkite/builder/commands/preview.rb +1 -13
  9. data/lib/buildkite/builder/commands/run.rb +21 -1
  10. data/lib/buildkite/builder/context.rb +108 -0
  11. data/lib/buildkite/builder/loaders/abstract.rb +6 -10
  12. data/lib/buildkite/builder/loaders/manifests.rb +1 -1
  13. data/lib/buildkite/builder/loaders/processors.rb +2 -2
  14. data/lib/buildkite/builder/loaders/templates.rb +1 -1
  15. data/lib/buildkite/builder/manifest.rb +1 -1
  16. data/lib/buildkite/builder/processors/abstract.rb +7 -7
  17. data/lib/buildkite/builder/rainbow.rb +1 -1
  18. data/lib/buildkite/pipelines.rb +1 -0
  19. data/lib/buildkite/pipelines/pipeline.rb +20 -9
  20. data/lib/buildkite/pipelines/step_context.rb +25 -0
  21. data/lib/buildkite/pipelines/steps/abstract.rb +9 -3
  22. data/lib/buildkite/pipelines/steps/block.rb +1 -0
  23. metadata +107 -25
  24. data/lib/buildkite/builder/runner.rb +0 -115
  25. data/lib/vendor/rainbow/Changelog.md +0 -101
  26. data/lib/vendor/rainbow/Gemfile +0 -30
  27. data/lib/vendor/rainbow/LICENSE +0 -20
  28. data/lib/vendor/rainbow/README.markdown +0 -225
  29. data/lib/vendor/rainbow/Rakefile +0 -11
  30. data/lib/vendor/rainbow/lib/rainbow.rb +0 -13
  31. data/lib/vendor/rainbow/lib/rainbow/color.rb +0 -150
  32. data/lib/vendor/rainbow/lib/rainbow/ext/string.rb +0 -64
  33. data/lib/vendor/rainbow/lib/rainbow/global.rb +0 -25
  34. data/lib/vendor/rainbow/lib/rainbow/null_presenter.rb +0 -100
  35. data/lib/vendor/rainbow/lib/rainbow/presenter.rb +0 -144
  36. data/lib/vendor/rainbow/lib/rainbow/refinement.rb +0 -14
  37. data/lib/vendor/rainbow/lib/rainbow/string_utils.rb +0 -22
  38. data/lib/vendor/rainbow/lib/rainbow/version.rb +0 -5
  39. data/lib/vendor/rainbow/lib/rainbow/wrapper.rb +0 -22
  40. data/lib/vendor/rainbow/lib/rainbow/x11_color_names.rb +0 -153
  41. data/lib/vendor/rainbow/rainbow.gemspec +0 -23
@@ -5,14 +5,14 @@ module Buildkite
5
5
  module Loaders
6
6
  class Abstract
7
7
  attr_reader :assets
8
- attr_reader :pipeline
8
+ attr_reader :root
9
9
 
10
- def self.load(pipeline)
11
- new(pipeline).assets
10
+ def self.load(root)
11
+ new(root).assets
12
12
  end
13
13
 
14
- def initialize(pipeline)
15
- @pipeline = pipeline
14
+ def initialize(root)
15
+ @root = root
16
16
  @assets = {}
17
17
  load
18
18
  end
@@ -20,11 +20,7 @@ module Buildkite
20
20
  private
21
21
 
22
22
  def buildkite_path
23
- Buildkite::Builder.root.join('.buildkite')
24
- end
25
-
26
- def pipeline_path
27
- buildkite_path.join("pipelines/#{pipeline}")
23
+ Builder.root.join(Builder::BUILDKITE_DIRECTORY_NAME)
28
24
  end
29
25
 
30
26
  def load
@@ -15,7 +15,7 @@ module Buildkite
15
15
  end
16
16
 
17
17
  def manifests_path
18
- pipeline_path.join(MANIFESTS_PATH)
18
+ root.join(MANIFESTS_PATH)
19
19
  end
20
20
  end
21
21
  end
@@ -19,7 +19,7 @@ module Buildkite
19
19
  return unless path.directory?
20
20
 
21
21
  path.children.map do |file|
22
- required_status = require(file)
22
+ required_status = require(file.to_s)
23
23
  add(file.basename, { required: required_status })
24
24
  end
25
25
  end
@@ -29,7 +29,7 @@ module Buildkite
29
29
  end
30
30
 
31
31
  def pipeline_processors_path
32
- pipeline_path.join(PROCESSORS_PATH)
32
+ root.join(PROCESSORS_PATH)
33
33
  end
34
34
  end
35
35
  end
@@ -17,7 +17,7 @@ module Buildkite
17
17
  end
18
18
 
19
19
  def templates_path
20
- pipeline_path.join(TEMPLATES_PATH)
20
+ root.join(TEMPLATES_PATH)
21
21
  end
22
22
  end
23
23
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'digest/md5'
4
4
  require 'pathname'
5
- require 'set'
5
+ require 'sorted_set'
6
6
 
7
7
  module Buildkite
8
8
  module Builder
@@ -7,12 +7,12 @@ module Buildkite
7
7
  include LoggingUtils
8
8
  using Rainbow
9
9
 
10
- def self.process(runner)
11
- new(runner).run
10
+ def self.process(context)
11
+ new(context).run
12
12
  end
13
13
 
14
- def initialize(runner)
15
- @runner = runner
14
+ def initialize(context)
15
+ @context = context
16
16
  end
17
17
 
18
18
  def run
@@ -21,18 +21,18 @@ module Buildkite
21
21
 
22
22
  private
23
23
 
24
- attr_reader :runner
24
+ attr_reader :context
25
25
 
26
26
  def process
27
27
  raise NotImplementedError
28
28
  end
29
29
 
30
30
  def log
31
- runner.log
31
+ context.logger
32
32
  end
33
33
 
34
34
  def pipeline
35
- runner.pipeline
35
+ context.pipeline
36
36
  end
37
37
 
38
38
  def buildkite
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../vendor/rainbow/lib/rainbow/refinement'
3
+ require 'rainbow/refinement'
4
4
 
5
5
  module Buildkite
6
6
  module Builder
@@ -8,6 +8,7 @@ module Buildkite
8
8
  autoload :Helpers, File.expand_path('pipelines/helpers', __dir__)
9
9
  autoload :Pipeline, File.expand_path('pipelines/pipeline', __dir__)
10
10
  autoload :Plugin, File.expand_path('pipelines/plugin', __dir__)
11
+ autoload :StepContext, File.expand_path('pipelines/step_context', __dir__)
11
12
  autoload :Steps, File.expand_path('pipelines/steps', __dir__)
12
13
  end
13
14
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+ require 'pathname'
4
5
 
5
6
  module Buildkite
6
7
  module Pipelines
@@ -15,6 +16,7 @@ module Buildkite
15
16
  @plugins = {}
16
17
  @templates = {}
17
18
  @processors = []
19
+ @notify = []
18
20
 
19
21
  instance_eval(&definition) if definition
20
22
  instance_eval(&block) if block_given?
@@ -26,8 +28,18 @@ module Buildkite
26
28
  Steps::Input,
27
29
  Steps::Trigger,
28
30
  ].each do |type|
29
- define_method(type.to_sym) do |template = nil, &block|
30
- add(type, template, &block)
31
+ define_method(type.to_sym) do |template = nil, **args, &block|
32
+ add(type, template, **args, &block)
33
+ end
34
+ end
35
+
36
+ def notify(*args)
37
+ if args.empty?
38
+ @notify
39
+ elsif args.first.is_a?(Hash)
40
+ @notify.push(args.first.transform_keys(&:to_s))
41
+ else
42
+ raise ArgumentError, 'value must be hash'
31
43
  end
32
44
  end
33
45
 
@@ -41,8 +53,8 @@ module Buildkite
41
53
  end
42
54
  end
43
55
 
44
- def skip(template = nil, &block)
45
- step = add(Steps::Skip, template, &block)
56
+ def skip(template = nil, **args, &block)
57
+ step = add(Steps::Skip, template, **args, &block)
46
58
  # A skip step has a nil/noop command.
47
59
  step.command(nil)
48
60
  # Always set the skip attribute if it's in a falsey state.
@@ -99,9 +111,8 @@ module Buildkite
99
111
 
100
112
  def to_h
101
113
  pipeline = {}
102
- if env.any?
103
- pipeline[:env] = env
104
- end
114
+ pipeline[:env] = env if env.any?
115
+ pipeline[:notify] = notify if notify.any?
105
116
  pipeline[:steps] = steps.map(&:to_h)
106
117
 
107
118
  Helpers.sanitize(pipeline)
@@ -113,8 +124,8 @@ module Buildkite
113
124
 
114
125
  private
115
126
 
116
- def add(step_class, template = nil, &block)
117
- steps.push(step_class.new(self, find_template(template), &block)).last
127
+ def add(step_class, template = nil, **args, &block)
128
+ steps.push(step_class.new(self, find_template(template), **args, &block)).last
118
129
  end
119
130
 
120
131
  def find_template(name)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buildkite
4
+ module Pipelines
5
+ class StepContext
6
+ attr_reader :step
7
+ attr_reader :args
8
+ attr_reader :data
9
+
10
+ def initialize(step, **args)
11
+ @step = step
12
+ @args = args
13
+ @data = {}
14
+ end
15
+
16
+ def pipeline
17
+ step.pipeline
18
+ end
19
+
20
+ def [](key)
21
+ args[key]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  module Buildkite
4
6
  module Pipelines
5
7
  module Steps
6
8
  class Abstract
9
+ extend Forwardable
7
10
  include Attributes
8
11
 
12
+ def_delegator :@context, :data
13
+
9
14
  attr_reader :pipeline
10
15
  attr_reader :template
11
16
 
@@ -13,12 +18,13 @@ module Buildkite
13
18
  name.split('::').last.downcase.to_sym
14
19
  end
15
20
 
16
- def initialize(pipeline, template = nil, &block)
21
+ def initialize(pipeline, template = nil, **args, &block)
17
22
  @pipeline = pipeline
18
23
  @template = template
24
+ @context = StepContext.new(self, **args)
19
25
 
20
- instance_eval(&template) if template
21
- instance_eval(&block) if block_given?
26
+ instance_exec(@context, &template) if template
27
+ instance_exec(@context, &block) if block_given?
22
28
  end
23
29
  end
24
30
  end
@@ -14,6 +14,7 @@ module Buildkite
14
14
  attribute :allow_dependency_failure
15
15
  attribute :branches
16
16
  attribute :fields
17
+ attribute :blocked_state
17
18
  end
18
19
  end
19
20
  end
metadata CHANGED
@@ -1,16 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
8
8
  - Andrew Lee
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-01 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2021-03-04 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
29
+ name: rainbow
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '3'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: byebug
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry-byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: webmock
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
14
112
  description: Buildkite Builder is a tool that provides projects using Buildkite to
15
113
  have dynamic pipeline functionality.
16
114
  email:
@@ -35,6 +133,7 @@ files:
35
133
  - lib/buildkite/builder/commands/files.rb
36
134
  - lib/buildkite/builder/commands/preview.rb
37
135
  - lib/buildkite/builder/commands/run.rb
136
+ - lib/buildkite/builder/context.rb
38
137
  - lib/buildkite/builder/definition.rb
39
138
  - lib/buildkite/builder/file_resolver.rb
40
139
  - lib/buildkite/builder/github.rb
@@ -49,7 +148,6 @@ files:
49
148
  - lib/buildkite/builder/processors.rb
50
149
  - lib/buildkite/builder/processors/abstract.rb
51
150
  - lib/buildkite/builder/rainbow.rb
52
- - lib/buildkite/builder/runner.rb
53
151
  - lib/buildkite/env.rb
54
152
  - lib/buildkite/pipelines.rb
55
153
  - lib/buildkite/pipelines/api.rb
@@ -68,6 +166,7 @@ files:
68
166
  - lib/buildkite/pipelines/helpers/timeout_in_minutes.rb
69
167
  - lib/buildkite/pipelines/pipeline.rb
70
168
  - lib/buildkite/pipelines/plugin.rb
169
+ - lib/buildkite/pipelines/step_context.rb
71
170
  - lib/buildkite/pipelines/steps.rb
72
171
  - lib/buildkite/pipelines/steps/abstract.rb
73
172
  - lib/buildkite/pipelines/steps/block.rb
@@ -76,23 +175,6 @@ files:
76
175
  - lib/buildkite/pipelines/steps/skip.rb
77
176
  - lib/buildkite/pipelines/steps/trigger.rb
78
177
  - lib/buildkite/pipelines/steps/wait.rb
79
- - lib/vendor/rainbow/Changelog.md
80
- - lib/vendor/rainbow/Gemfile
81
- - lib/vendor/rainbow/LICENSE
82
- - lib/vendor/rainbow/README.markdown
83
- - lib/vendor/rainbow/Rakefile
84
- - lib/vendor/rainbow/lib/rainbow.rb
85
- - lib/vendor/rainbow/lib/rainbow/color.rb
86
- - lib/vendor/rainbow/lib/rainbow/ext/string.rb
87
- - lib/vendor/rainbow/lib/rainbow/global.rb
88
- - lib/vendor/rainbow/lib/rainbow/null_presenter.rb
89
- - lib/vendor/rainbow/lib/rainbow/presenter.rb
90
- - lib/vendor/rainbow/lib/rainbow/refinement.rb
91
- - lib/vendor/rainbow/lib/rainbow/string_utils.rb
92
- - lib/vendor/rainbow/lib/rainbow/version.rb
93
- - lib/vendor/rainbow/lib/rainbow/wrapper.rb
94
- - lib/vendor/rainbow/lib/rainbow/x11_color_names.rb
95
- - lib/vendor/rainbow/rainbow.gemspec
96
178
  homepage: https://github.com/Gusto/buildkite-builder
97
179
  licenses:
98
180
  - MIT
@@ -101,7 +183,7 @@ metadata:
101
183
  source_code_uri: https://github.com/Gusto/buildkite-builder
102
184
  changelog_uri: https://github.com/Gusto/buildkite-builder/blob/master/CHANGELOG.md
103
185
  bug_tracker_uri: https://github.com/Gusto/buildkite-builder/issues
104
- post_install_message:
186
+ post_install_message:
105
187
  rdoc_options: []
106
188
  require_paths:
107
189
  - lib
@@ -116,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
198
  - !ruby/object:Gem::Version
117
199
  version: '0'
118
200
  requirements: []
119
- rubygems_version: 3.1.2
120
- signing_key:
201
+ rubygems_version: 3.2.2
202
+ signing_key:
121
203
  specification_version: 4
122
204
  summary: A gem for programmatically creating Buildkite pipelines.
123
205
  test_files: []