buildkite-builder 3.1.0 → 3.3.1

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: bef719c816c5d64756bbcd041ca2a3fabe8fe59bff47cc154948207ce64a672f
4
- data.tar.gz: f25762b1422e540f395526df9d6082e1d5908ea0b9b290bf025a365b56c317ff
3
+ metadata.gz: ad16f8a66cf5c9c52bbbce15ccbd29589294309739a63f67a8982403f51b9b36
4
+ data.tar.gz: d148df13c7489629bb2d23c772fa309f937cf65ceafd46eb0303d199b4292f0b
5
5
  SHA512:
6
- metadata.gz: c00f3fba91b34cf907c99ff839612270ef8aecb754c988af52226e979d5e743a508963d1d06d9957b529a2e3ba47cf6ba0951ec33290b8581dc9937b4178033a
7
- data.tar.gz: 6e62bff8ecdb50b72bdb3afb8fd6fa1385f17ef1852b607f5273570cab1d396ee65d8908a78604d48ccb7a564ad4cb0f9dbff6b94b7a016cfd9ee881e1d4098a
6
+ metadata.gz: 7be78bd7cf1891adaf95c557861c6f5b8cc8b16e28ecabae1406eba44526e0e16fc13df245d253f73892dae0324255d2ecb6837643ef1058b18bfdb87801521b
7
+ data.tar.gz: 2ae512dbf1f76794531d5f4ef278fffc061e10d21074d8eb0de7454cc55b2dc50b61c5b30695152283790234a3a9da52ccd4b734067ed7bdc90b7898304feec9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 3.3.1
2
+ * Add support to iterate over subpipelines.
3
+ * Allow build options to be passed to subpipelines.
4
+
5
+ ## 3.3.0
6
+ * Remove arguments in sub-pipeline's trigger step setup and use dsl delegation instead.
7
+
8
+ ## 3.2.0
9
+ * Remove `template` from sub-pipeline trigger step setup and use arguments instead.
10
+
1
11
  ## 3.1.0
2
12
  * 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
13
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.3.1
@@ -7,35 +7,50 @@ module Buildkite
7
7
  class Pipeline
8
8
  include Buildkite::Pipelines::Attributes
9
9
 
10
- attr_reader :data, :name
10
+ attr_reader :data, :name, :dsl
11
11
 
12
- attribute :depends_on, append: true
12
+ # These attributes are for triggered step
13
+ attribute :label
13
14
  attribute :key
15
+ attribute :skip
16
+ attribute :if, as: :condition
17
+ attribute :depends_on, append: true
18
+ attribute :allow_dependency_failure
19
+ attribute :branches
20
+ attribute :async
21
+ attribute :build
14
22
 
15
23
  def self.to_sym
16
24
  name.split('::').last.downcase.to_sym
17
25
  end
18
26
 
19
- def initialize(name, steps, &block)
27
+ def initialize(name, context, &block)
28
+ @context = context
20
29
  @name = name
21
30
  @data = Data.new
22
31
  @data.steps = StepCollection.new(
23
- steps.templates,
24
- steps.plugins
32
+ context.data.steps.templates,
33
+ context.data.steps.plugins
25
34
  )
26
35
  @data.notify = []
27
36
  @data.env = {}
28
37
 
29
- @dsl = Dsl.new(self)
30
- @dsl.extend(Extensions::Steps)
31
- @dsl.extend(Extensions::Notify)
32
- @dsl.extend(Extensions::Env)
38
+ # Use `clone` to copy over dsl's extended extensions
39
+ @dsl = context.dsl.clone
40
+ # Override dsl context to current pipeline
41
+ @dsl.instance_variable_set(:@context, self)
42
+
33
43
  instance_eval(&block) if block_given?
34
44
  self
35
45
  end
36
46
 
37
47
  def to_h
38
48
  attributes = super
49
+ # Merge envs from main pipeline, since ruby does not have `reverse_merge` and
50
+ # `data` does not allow keys override, we have to reset the data hash per key.
51
+ @context.data.env.merge(data.env).each do |key, value|
52
+ data.env[key] = value
53
+ end
39
54
  attributes.merge(data.to_definition)
40
55
  end
41
56
 
@@ -53,41 +68,38 @@ module Buildkite
53
68
  end
54
69
 
55
70
  dsl do
56
- def pipeline(name, template = nil, &block)
71
+ def pipeline(name, &block)
57
72
  raise "Subpipeline must have a name" if name.empty?
58
73
  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
74
 
75
+ sub_pipeline = Buildkite::Builder::Extensions::SubPipelines::Pipeline.new(name, context, &block)
61
76
  context.data.pipelines.add(sub_pipeline)
62
77
 
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
78
+ trigger_step = context.data.steps.add(Pipelines::Steps::Trigger)
79
+ trigger_step.trigger(name)
80
+
81
+ build_options = {
82
+ message: '${BUILDKITE_MESSAGE}',
83
+ commit: '${BUILDKITE_COMMIT}',
84
+ branch: '${BUILDKITE_BRANCH}',
85
+ env: {
86
+ BUILDKITE_PULL_REQUEST: '${BUILDKITE_PULL_REQUEST}',
87
+ BUILDKITE_PULL_REQUEST_BASE_BRANCH: '${BUILDKITE_PULL_REQUEST_BASE_BRANCH}',
88
+ BUILDKITE_PULL_REQUEST_REPO: '${BUILDKITE_PULL_REQUEST_REPO}',
89
+ BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml
90
+ }
91
+ }
92
+ build_options.merge!(sub_pipeline.build) if sub_pipeline.build
93
+
94
+ trigger_step.build(build_options)
95
+ trigger_step.key(sub_pipeline.key || "subpipeline_#{name}_#{context.data.pipelines.count}")
96
+ trigger_step.label(sub_pipeline.label || name.capitalize)
97
+ trigger_step.async(sub_pipeline.async || false)
98
+ trigger_step.branches(sub_pipeline.branches) if sub_pipeline.branches
99
+ trigger_step.condition(sub_pipeline.condition) if sub_pipeline.condition
100
+ trigger_step.depends_on(*sub_pipeline.get('depends_on')) if sub_pipeline.get('depends_on')
101
+ trigger_step.allow_dependency_failure(sub_pipeline.allow_dependency_failure || false)
102
+ trigger_step.skip(sub_pipeline.skip || false)
91
103
  end
92
104
  end
93
105
  end
@@ -8,6 +8,7 @@ module Buildkite
8
8
  attr_reader :pipelines
9
9
 
10
10
  def_delegator :@pipelines, :count
11
+ def_delegator :@pipelines, :each
11
12
 
12
13
  def initialize(artifacts)
13
14
  @artifacts = artifacts
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.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: 2022-06-08 00:00:00.000000000 Z
12
+ date: 2022-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -177,7 +177,7 @@ metadata:
177
177
  source_code_uri: https://github.com/Gusto/buildkite-builder
178
178
  changelog_uri: https://github.com/Gusto/buildkite-builder/blob/master/CHANGELOG.md
179
179
  bug_tracker_uri: https://github.com/Gusto/buildkite-builder/issues
180
- post_install_message:
180
+ post_install_message:
181
181
  rdoc_options: []
182
182
  require_paths:
183
183
  - lib
@@ -192,8 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubygems_version: 3.2.32
196
- signing_key:
195
+ rubygems_version: 3.0.3.1
196
+ signing_key:
197
197
  specification_version: 4
198
198
  summary: A gem for programmatically creating Buildkite pipelines.
199
199
  test_files: []