buildkite-builder 3.0.0 → 3.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +34 -4
- data/VERSION +1 -1
- data/lib/buildkite/builder/data.rb +1 -1
- data/lib/buildkite/builder/extensions/sub_pipelines.rb +96 -0
- data/lib/buildkite/builder/extensions.rb +1 -0
- data/lib/buildkite/builder/pipeline.rb +1 -0
- data/lib/buildkite/builder/pipeline_collection.rb +39 -0
- data/lib/buildkite/builder.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bef719c816c5d64756bbcd041ca2a3fabe8fe59bff47cc154948207ce64a672f
|
4
|
+
data.tar.gz: f25762b1422e540f395526df9d6082e1d5908ea0b9b290bf025a365b56c317ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c00f3fba91b34cf907c99ff839612270ef8aecb754c988af52226e979d5e743a508963d1d06d9957b529a2e3ba47cf6ba0951ec33290b8581dc9937b4178033a
|
7
|
+
data.tar.gz: 6e62bff8ecdb50b72bdb3afb8fd6fa1385f17ef1852b607f5273570cab1d396ee65d8908a78604d48ccb7a564ad4cb0f9dbff6b94b7a016cfd9ee881e1d4098a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 3.1.0
|
2
|
+
* Add subpipeline support to save triggered pipeline's YML definition beforehand to artifacts and pass down the file to an ENV for pipeline setup.
|
3
|
+
|
1
4
|
## 3.0.0
|
2
5
|
* Remove manifest features to prevent Github API dependency and simplify the gem to focus on Buildkite features.
|
3
6
|
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ At its core, BKB is really just a YAML builder. This tool allows you to scale yo
|
|
48
48
|
- Perform pre-build code/diff analysis to determine whether or not to to add a step to the pipeline.
|
49
49
|
- Reorder pipeline steps dynamically.
|
50
50
|
- Augment your pipeline steps with BKB processors.
|
51
|
-
|
51
|
+
|
52
52
|
### Pipeline Files
|
53
53
|
|
54
54
|
Your repo can contain as many pipeline definitions as you'd like. By convention, pipeline file structure are as such:
|
@@ -74,9 +74,9 @@ Buildkite::Builder.pipeline do
|
|
74
74
|
label "Rspec", emoji: :rspec
|
75
75
|
command "bundle exec rspec"
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
wait
|
79
|
-
|
79
|
+
|
80
80
|
trigger do
|
81
81
|
trigger "deploy-pipeline"
|
82
82
|
end
|
@@ -127,7 +127,7 @@ You can then include the template into the the pipeline once or as many time as
|
|
127
127
|
```ruby
|
128
128
|
Buildkite::Builder.pipeline do
|
129
129
|
command(:rspec)
|
130
|
-
|
130
|
+
|
131
131
|
# Reuse and agument templates on the fly.
|
132
132
|
command(:rspec) do
|
133
133
|
label "Run RSpec again!"
|
@@ -135,6 +135,36 @@ Buildkite::Builder.pipeline do
|
|
135
135
|
end
|
136
136
|
```
|
137
137
|
|
138
|
+
### Subpipeline
|
139
|
+
|
140
|
+
While triggering another pipeline, you can predefine subpipeline's steps using `pipeline(NAME_OF_SUBPIPELINE)` in the main pipeline's `pipeline.rb` file and share with main pipeline's plugins and templates definition.
|
141
|
+
|
142
|
+
`.buildkite/pipelines/pipeline-triggerer/pipeline.rb`
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
Buildkite::Builder.pipeline do
|
146
|
+
pipeline('rspec-pipeline') do
|
147
|
+
command do
|
148
|
+
label "Run RSpec in separate pipeline"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
Inside your Buildkite pipeline setup, you can do the following:
|
155
|
+
|
156
|
+
In `https://buildkite.com/your-org/rspec-pipeline/steps`
|
157
|
+
|
158
|
+
```yaml
|
159
|
+
steps:
|
160
|
+
- label: ":pipeline:"
|
161
|
+
commands:
|
162
|
+
- buildkite-agent artifact download $BKB_SUBPIPELINE_FILE . --build $BUILDKITE_TRIGGERED_FROM_BUILD_ID
|
163
|
+
- buildkite-agent pipeline upload $BKB_SUBPIPELINE_FILE
|
164
|
+
```
|
165
|
+
|
166
|
+
This will upload the pregenerated `pipeline.yml` to `rspec-pipeline`.
|
167
|
+
|
138
168
|
## Development
|
139
169
|
|
140
170
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.0
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Builder
|
5
|
+
module Extensions
|
6
|
+
class SubPipelines < Extension
|
7
|
+
class Pipeline
|
8
|
+
include Buildkite::Pipelines::Attributes
|
9
|
+
|
10
|
+
attr_reader :data, :name
|
11
|
+
|
12
|
+
attribute :depends_on, append: true
|
13
|
+
attribute :key
|
14
|
+
|
15
|
+
def self.to_sym
|
16
|
+
name.split('::').last.downcase.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(name, steps, &block)
|
20
|
+
@name = name
|
21
|
+
@data = Data.new
|
22
|
+
@data.steps = StepCollection.new(
|
23
|
+
steps.templates,
|
24
|
+
steps.plugins
|
25
|
+
)
|
26
|
+
@data.notify = []
|
27
|
+
@data.env = {}
|
28
|
+
|
29
|
+
@dsl = Dsl.new(self)
|
30
|
+
@dsl.extend(Extensions::Steps)
|
31
|
+
@dsl.extend(Extensions::Notify)
|
32
|
+
@dsl.extend(Extensions::Env)
|
33
|
+
instance_eval(&block) if block_given?
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h
|
38
|
+
attributes = super
|
39
|
+
attributes.merge(data.to_definition)
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(method_name, *args, **kwargs, &_block)
|
43
|
+
@dsl.public_send(method_name, *args, **kwargs, &_block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def pipeline_yml
|
47
|
+
@pipeline_yml ||= "tmp/buildkite-builder/#{SecureRandom.urlsafe_base64}.yml"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def prepare
|
52
|
+
context.data.pipelines = PipelineCollection.new(context.artifacts)
|
53
|
+
end
|
54
|
+
|
55
|
+
dsl do
|
56
|
+
def pipeline(name, template = nil, &block)
|
57
|
+
raise "Subpipeline must have a name" if name.empty?
|
58
|
+
raise "Subpipeline does not allow nested in another Subpipeline" if context.is_a?(Buildkite::Builder::Extensions::SubPipelines::Pipeline)
|
59
|
+
sub_pipeline = Buildkite::Builder::Extensions::SubPipelines::Pipeline.new(name, context.data.steps, &block)
|
60
|
+
|
61
|
+
context.data.pipelines.add(sub_pipeline)
|
62
|
+
|
63
|
+
if template
|
64
|
+
# Use predefined template
|
65
|
+
step = context.data.steps.add(Pipelines::Steps::Trigger, template)
|
66
|
+
|
67
|
+
if step.build.nil?
|
68
|
+
step.build(env: { BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml })
|
69
|
+
else
|
70
|
+
step.build[:env].merge!(BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml)
|
71
|
+
end
|
72
|
+
else
|
73
|
+
# Generic trigger step
|
74
|
+
context.data.steps.add(Pipelines::Steps::Trigger, key: "subpipeline_#{name}_#{context.data.pipelines.count}") do |context|
|
75
|
+
key context[:key]
|
76
|
+
label name.capitalize
|
77
|
+
trigger name
|
78
|
+
build(
|
79
|
+
message: '${BUILDKITE_MESSAGE}',
|
80
|
+
commit: '${BUILDKITE_COMMIT}',
|
81
|
+
branch: '${BUILDKITE_BRANCH}',
|
82
|
+
env: {
|
83
|
+
BUILDKITE_PULL_REQUEST: '${BUILDKITE_PULL_REQUEST}',
|
84
|
+
BUILDKITE_PULL_REQUEST_BASE_BRANCH: '${BUILDKITE_PULL_REQUEST_BASE_BRANCH}',
|
85
|
+
BUILDKITE_PULL_REQUEST_REPO: '${BUILDKITE_PULL_REQUEST_REPO}',
|
86
|
+
BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml
|
87
|
+
}
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -6,6 +6,7 @@ module Buildkite
|
|
6
6
|
autoload :Env, File.expand_path('extensions/env', __dir__)
|
7
7
|
autoload :Lib, File.expand_path('extensions/lib', __dir__)
|
8
8
|
autoload :Notify, File.expand_path('extensions/notify', __dir__)
|
9
|
+
autoload :SubPipelines, File.expand_path('extensions/sub_pipelines', __dir__)
|
9
10
|
autoload :Steps, File.expand_path('extensions/steps', __dir__)
|
10
11
|
autoload :Use, File.expand_path('extensions/use', __dir__)
|
11
12
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Builder
|
5
|
+
class PipelineCollection
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :pipelines
|
9
|
+
|
10
|
+
def_delegator :@pipelines, :count
|
11
|
+
|
12
|
+
def initialize(artifacts)
|
13
|
+
@artifacts = artifacts
|
14
|
+
@pipelines = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def add(pipeline)
|
18
|
+
unless pipeline.is_a?(Buildkite::Builder::Extensions::SubPipelines::Pipeline)
|
19
|
+
raise "`#{pipeline}` must be a Buildkite::Builder::Extensions::SubPipelines::Pipeline"
|
20
|
+
end
|
21
|
+
|
22
|
+
pipelines << pipeline
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_definition
|
26
|
+
# Instead of generates pipeline.yml, subpipelines save generated file to artifacts
|
27
|
+
pipelines.each do |pipeline|
|
28
|
+
file = Pathname.new(pipeline.pipeline_yml)
|
29
|
+
file.dirname.mkpath
|
30
|
+
file.write(YAML.dump(Pipelines::Helpers.sanitize(pipeline.to_h)))
|
31
|
+
|
32
|
+
@artifacts << file
|
33
|
+
end
|
34
|
+
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/buildkite/builder.rb
CHANGED
@@ -20,6 +20,7 @@ module Buildkite
|
|
20
20
|
autoload :Plugin, File.expand_path('builder/plugin', __dir__)
|
21
21
|
autoload :PluginCollection, File.expand_path('builder/plugin_collection', __dir__)
|
22
22
|
autoload :StepCollection, File.expand_path('builder/step_collection', __dir__)
|
23
|
+
autoload :PipelineCollection, File.expand_path('builder/pipeline_collection', __dir__)
|
23
24
|
autoload :TemplateManager, File.expand_path('builder/template_manager', __dir__)
|
24
25
|
autoload :PluginManager, File.expand_path('builder/plugin_manager', __dir__)
|
25
26
|
|
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: 3.
|
4
|
+
version: 3.1.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: 2022-
|
12
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rainbow
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/buildkite/builder/extensions/lib.rb
|
129
129
|
- lib/buildkite/builder/extensions/notify.rb
|
130
130
|
- lib/buildkite/builder/extensions/steps.rb
|
131
|
+
- lib/buildkite/builder/extensions/sub_pipelines.rb
|
131
132
|
- lib/buildkite/builder/extensions/use.rb
|
132
133
|
- lib/buildkite/builder/group.rb
|
133
134
|
- lib/buildkite/builder/loaders.rb
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- lib/buildkite/builder/loaders/templates.rb
|
137
138
|
- lib/buildkite/builder/logging_utils.rb
|
138
139
|
- lib/buildkite/builder/pipeline.rb
|
140
|
+
- lib/buildkite/builder/pipeline_collection.rb
|
139
141
|
- lib/buildkite/builder/plugin.rb
|
140
142
|
- lib/buildkite/builder/plugin_collection.rb
|
141
143
|
- lib/buildkite/builder/plugin_manager.rb
|
@@ -190,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
192
|
- !ruby/object:Gem::Version
|
191
193
|
version: '0'
|
192
194
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
195
|
+
rubygems_version: 3.2.32
|
194
196
|
signing_key:
|
195
197
|
specification_version: 4
|
196
198
|
summary: A gem for programmatically creating Buildkite pipelines.
|