buildkite-builder 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bef719c816c5d64756bbcd041ca2a3fabe8fe59bff47cc154948207ce64a672f
4
- data.tar.gz: f25762b1422e540f395526df9d6082e1d5908ea0b9b290bf025a365b56c317ff
3
+ metadata.gz: d50f76bdcfda9a7561fce2b86dbae5b0ea99d37c0dbd6c763b35541a39e904c8
4
+ data.tar.gz: 2fbd91625db37b0bf88546931254b4f4024de25d3d20d09267318eafae2e3646
5
5
  SHA512:
6
- metadata.gz: c00f3fba91b34cf907c99ff839612270ef8aecb754c988af52226e979d5e743a508963d1d06d9957b529a2e3ba47cf6ba0951ec33290b8581dc9937b4178033a
7
- data.tar.gz: 6e62bff8ecdb50b72bdb3afb8fd6fa1385f17ef1852b607f5273570cab1d396ee65d8908a78604d48ccb7a564ad4cb0f9dbff6b94b7a016cfd9ee881e1d4098a
6
+ metadata.gz: 5902b46da66c6ec7828d1bdf4f148f5445f2c7820e9f209e4a7ea22dae1ac8e62ea397660cca1f512737681c4c9397b97d5361f0fd64dba95066cb32751489ad
7
+ data.tar.gz: f67169e9bbdb7b84ccc1a6a8fec9593e878b70759e74f7236f595a3772649ce140d3ae99a329e090fb514c9bbbb450d70e58ea6362459404bced23f4a575cab1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.2.0
2
+ * Remove `template` from sub-pipeline trigger step setup and use arguments instead.
3
+
1
4
  ## 3.1.0
2
5
  * 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
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.2.0
@@ -7,7 +7,7 @@ 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
12
  attribute :depends_on, append: true
13
13
  attribute :key
@@ -16,26 +16,33 @@ module Buildkite
16
16
  name.split('::').last.downcase.to_sym
17
17
  end
18
18
 
19
- def initialize(name, steps, &block)
19
+ def initialize(name, context, &block)
20
+ @context = context
20
21
  @name = name
21
22
  @data = Data.new
22
23
  @data.steps = StepCollection.new(
23
- steps.templates,
24
- steps.plugins
24
+ context.data.steps.templates,
25
+ context.data.steps.plugins
25
26
  )
26
27
  @data.notify = []
27
28
  @data.env = {}
28
29
 
29
- @dsl = Dsl.new(self)
30
- @dsl.extend(Extensions::Steps)
31
- @dsl.extend(Extensions::Notify)
32
- @dsl.extend(Extensions::Env)
30
+ # Use `clone` to copy over dsl's extended extensions
31
+ @dsl = context.dsl.clone
32
+ # Override dsl context to current pipeline
33
+ @dsl.instance_variable_set(:@context, self)
34
+
33
35
  instance_eval(&block) if block_given?
34
36
  self
35
37
  end
36
38
 
37
39
  def to_h
38
40
  attributes = super
41
+ # Merge envs from main pipeline, since ruby does not have `reverse_merge` and
42
+ # `data` does not allow keys override, we have to reset the data hash per key.
43
+ @context.data.env.merge(data.env).each do |key, value|
44
+ data.env[key] = value
45
+ end
39
46
  attributes.merge(data.to_definition)
40
47
  end
41
48
 
@@ -53,40 +60,43 @@ module Buildkite
53
60
  end
54
61
 
55
62
  dsl do
56
- def pipeline(name, template = nil, &block)
63
+ def pipeline(name, **options, &block)
57
64
  raise "Subpipeline must have a name" if name.empty?
58
65
  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
66
 
67
+ sub_pipeline = Buildkite::Builder::Extensions::SubPipelines::Pipeline.new(name, context, &block)
61
68
  context.data.pipelines.add(sub_pipeline)
62
69
 
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
70
+ options = options.slice(:key, :label, :async, :branches, :condition, :depends_on, :allow_dependency_failure, :skip, :emoji)
71
+ options[:key] ||= "subpipeline_#{name}_#{context.data.pipelines.count}"
72
+ options[:label] ||= name.capitalize
73
+
74
+ if options[:emoji]
75
+ emoji = Array(options.delete(:emoji)).map { |name| ":#{name}:" }.join
76
+ options[:label] = [emoji, options[:label]].compact.join(' ')
77
+ end
78
+
79
+ context.data.steps.add(Pipelines::Steps::Trigger, **options) do |context|
80
+ key context[:key]
81
+ label context[:label]
82
+ trigger name
83
+ build(
84
+ message: '${BUILDKITE_MESSAGE}',
85
+ commit: '${BUILDKITE_COMMIT}',
86
+ branch: '${BUILDKITE_BRANCH}',
87
+ env: {
88
+ BUILDKITE_PULL_REQUEST: '${BUILDKITE_PULL_REQUEST}',
89
+ BUILDKITE_PULL_REQUEST_BASE_BRANCH: '${BUILDKITE_PULL_REQUEST_BASE_BRANCH}',
90
+ BUILDKITE_PULL_REQUEST_REPO: '${BUILDKITE_PULL_REQUEST_REPO}',
91
+ BKB_SUBPIPELINE_FILE: sub_pipeline.pipeline_yml
92
+ }
93
+ )
94
+ async context[:async] || false
95
+ branches context[:branches] if context[:branches]
96
+ condition context[:condition] if context[:condition]
97
+ depends_on *context[:depends_on] if context[:depends_on]
98
+ allow_dependency_failure context[:allow_dependency_failure] || false
99
+ skip context[:skip] || false
90
100
  end
91
101
  end
92
102
  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: 3.1.0
4
+ version: 3.2.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-06-08 00:00:00.000000000 Z
12
+ date: 2022-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow