buildkite-builder 1.0.0.beta.5 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +118 -14
  4. data/VERSION +1 -0
  5. data/lib/buildkite/builder.rb +12 -18
  6. data/lib/buildkite/builder/commands/abstract.rb +49 -4
  7. data/lib/buildkite/builder/commands/preview.rb +1 -13
  8. data/lib/buildkite/builder/commands/run.rb +21 -1
  9. data/lib/buildkite/builder/context.rb +108 -0
  10. data/lib/buildkite/builder/loaders/abstract.rb +6 -10
  11. data/lib/buildkite/builder/loaders/manifests.rb +1 -1
  12. data/lib/buildkite/builder/loaders/processors.rb +2 -2
  13. data/lib/buildkite/builder/loaders/templates.rb +1 -1
  14. data/lib/buildkite/builder/manifest.rb +1 -1
  15. data/lib/buildkite/builder/processors/abstract.rb +7 -7
  16. data/lib/buildkite/builder/rainbow.rb +1 -1
  17. data/lib/buildkite/pipelines.rb +1 -0
  18. data/lib/buildkite/pipelines/pipeline.rb +20 -9
  19. data/lib/buildkite/pipelines/step_context.rb +25 -0
  20. data/lib/buildkite/pipelines/steps/abstract.rb +9 -3
  21. data/lib/buildkite/pipelines/steps/block.rb +1 -0
  22. metadata +110 -27
  23. data/lib/buildkite/builder/runner.rb +0 -114
  24. data/lib/vendor/rainbow/Changelog.md +0 -101
  25. data/lib/vendor/rainbow/Gemfile +0 -30
  26. data/lib/vendor/rainbow/LICENSE +0 -20
  27. data/lib/vendor/rainbow/README.markdown +0 -225
  28. data/lib/vendor/rainbow/Rakefile +0 -11
  29. data/lib/vendor/rainbow/lib/rainbow.rb +0 -13
  30. data/lib/vendor/rainbow/lib/rainbow/color.rb +0 -150
  31. data/lib/vendor/rainbow/lib/rainbow/ext/string.rb +0 -64
  32. data/lib/vendor/rainbow/lib/rainbow/global.rb +0 -25
  33. data/lib/vendor/rainbow/lib/rainbow/null_presenter.rb +0 -100
  34. data/lib/vendor/rainbow/lib/rainbow/presenter.rb +0 -144
  35. data/lib/vendor/rainbow/lib/rainbow/refinement.rb +0 -14
  36. data/lib/vendor/rainbow/lib/rainbow/string_utils.rb +0 -22
  37. data/lib/vendor/rainbow/lib/rainbow/version.rb +0 -5
  38. data/lib/vendor/rainbow/lib/rainbow/wrapper.rb +0 -22
  39. data/lib/vendor/rainbow/lib/rainbow/x11_color_names.rb +0 -153
  40. 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.beta.5
4
+ version: 1.3.1
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-02 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:
@@ -23,6 +121,7 @@ files:
23
121
  - CHANGELOG.md
24
122
  - LICENSE.txt
25
123
  - README.md
124
+ - VERSION
26
125
  - bin/buildkite-builder
27
126
  - bin/console
28
127
  - bin/setup
@@ -34,6 +133,7 @@ files:
34
133
  - lib/buildkite/builder/commands/files.rb
35
134
  - lib/buildkite/builder/commands/preview.rb
36
135
  - lib/buildkite/builder/commands/run.rb
136
+ - lib/buildkite/builder/context.rb
37
137
  - lib/buildkite/builder/definition.rb
38
138
  - lib/buildkite/builder/file_resolver.rb
39
139
  - lib/buildkite/builder/github.rb
@@ -48,7 +148,6 @@ files:
48
148
  - lib/buildkite/builder/processors.rb
49
149
  - lib/buildkite/builder/processors/abstract.rb
50
150
  - lib/buildkite/builder/rainbow.rb
51
- - lib/buildkite/builder/runner.rb
52
151
  - lib/buildkite/env.rb
53
152
  - lib/buildkite/pipelines.rb
54
153
  - lib/buildkite/pipelines/api.rb
@@ -67,6 +166,7 @@ files:
67
166
  - lib/buildkite/pipelines/helpers/timeout_in_minutes.rb
68
167
  - lib/buildkite/pipelines/pipeline.rb
69
168
  - lib/buildkite/pipelines/plugin.rb
169
+ - lib/buildkite/pipelines/step_context.rb
70
170
  - lib/buildkite/pipelines/steps.rb
71
171
  - lib/buildkite/pipelines/steps/abstract.rb
72
172
  - lib/buildkite/pipelines/steps/block.rb
@@ -75,23 +175,6 @@ files:
75
175
  - lib/buildkite/pipelines/steps/skip.rb
76
176
  - lib/buildkite/pipelines/steps/trigger.rb
77
177
  - lib/buildkite/pipelines/steps/wait.rb
78
- - lib/vendor/rainbow/Changelog.md
79
- - lib/vendor/rainbow/Gemfile
80
- - lib/vendor/rainbow/LICENSE
81
- - lib/vendor/rainbow/README.markdown
82
- - lib/vendor/rainbow/Rakefile
83
- - lib/vendor/rainbow/lib/rainbow.rb
84
- - lib/vendor/rainbow/lib/rainbow/color.rb
85
- - lib/vendor/rainbow/lib/rainbow/ext/string.rb
86
- - lib/vendor/rainbow/lib/rainbow/global.rb
87
- - lib/vendor/rainbow/lib/rainbow/null_presenter.rb
88
- - lib/vendor/rainbow/lib/rainbow/presenter.rb
89
- - lib/vendor/rainbow/lib/rainbow/refinement.rb
90
- - lib/vendor/rainbow/lib/rainbow/string_utils.rb
91
- - lib/vendor/rainbow/lib/rainbow/version.rb
92
- - lib/vendor/rainbow/lib/rainbow/wrapper.rb
93
- - lib/vendor/rainbow/lib/rainbow/x11_color_names.rb
94
- - lib/vendor/rainbow/rainbow.gemspec
95
178
  homepage: https://github.com/Gusto/buildkite-builder
96
179
  licenses:
97
180
  - MIT
@@ -100,7 +183,7 @@ metadata:
100
183
  source_code_uri: https://github.com/Gusto/buildkite-builder
101
184
  changelog_uri: https://github.com/Gusto/buildkite-builder/blob/master/CHANGELOG.md
102
185
  bug_tracker_uri: https://github.com/Gusto/buildkite-builder/issues
103
- post_install_message:
186
+ post_install_message:
104
187
  rdoc_options: []
105
188
  require_paths:
106
189
  - lib
@@ -111,12 +194,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
194
  version: 2.3.0
112
195
  required_rubygems_version: !ruby/object:Gem::Requirement
113
196
  requirements:
114
- - - ">"
197
+ - - ">="
115
198
  - !ruby/object:Gem::Version
116
- version: 1.3.1
199
+ version: '0'
117
200
  requirements: []
118
- rubygems_version: 3.1.2
119
- signing_key:
201
+ rubygems_version: 3.2.2
202
+ signing_key:
120
203
  specification_version: 4
121
204
  summary: A gem for programmatically creating Buildkite pipelines.
122
205
  test_files: []