buildkite-builder 4.1.0 → 4.1.2

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: c1f1ed1d180d7e0682417a8ada846785b485c32af561a442c9d2e6370975de1f
4
- data.tar.gz: c618bcd175b11c4dccb1b1f40d642ce7286b05b5c5d9fd42693e060d0602c2f4
3
+ metadata.gz: 1a02f80263e1373648688276099006c4d2c6870803bb82196cdce5be97d89ad5
4
+ data.tar.gz: bee2180eac619b4bc4931434f12e02d199fd95c82bcf43e9798b96d01f76f263
5
5
  SHA512:
6
- metadata.gz: 4e45d32dfedd02df0fba24ba0ac59ae388dc4c4d909e26c7fa6672944ba637959352a73619b6629b9d5ea3c89b94a974f93a1c50c182a08bf9ede5092438fb52
7
- data.tar.gz: d428745b5ffd07191f5bcd375ff7aaa4043ccc2fda09733c3569f34658b377b00cdd63d3ea8b46c0d1ce28524519a6c9701e44c720afee4c9393da8f4d4de17d
6
+ metadata.gz: c8f8028dbc2b311ed71a5dd287d805e8cf417832495172405e2d5556f6535163ab5400a8506c7c9ecd0a32099a0cf7283c32f854f86781c1615284e3032c9319
7
+ data.tar.gz: eda46a592c6f8630e177f539369c3bbf1d619429b32407db7fbf461420592ef9263982dbe4ed4e6f0203baeac8a5a06362aa493e5a6b26680a52f05c904f73f2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.1.0
1
+ 4.1.2
@@ -14,7 +14,7 @@ module Buildkite
14
14
 
15
15
  def build(name, attributes = {})
16
16
  plugin = @plugins[name.to_s]
17
- raise(ArgumentError, "Plugin is not registered: #{resource}") unless plugin
17
+ raise(ArgumentError, "Plugin is not registered: #{name}") unless plugin
18
18
 
19
19
  { plugin.uri => plugin.default_attributes.merge(attributes) }
20
20
  end
@@ -5,6 +5,8 @@ require 'open3'
5
5
  module Buildkite
6
6
  module Pipelines
7
7
  class Command
8
+ class CommandFailedError < StandardError; end
9
+
8
10
  BIN_PATH = 'buildkite-agent'
9
11
  COMMANDS = %w(
10
12
  pipeline
@@ -14,36 +16,38 @@ module Buildkite
14
16
  )
15
17
 
16
18
  class << self
17
- def pipeline(subcommand, *args)
18
- new(:pipeline, subcommand, *args).run
19
+ def pipeline(subcommand, *args, exception: false)
20
+ new(:pipeline, subcommand, *args).run(exception: exception)
19
21
  end
20
22
 
21
- def artifact(subcommand, *args)
23
+ def artifact(subcommand, *args, exception: false)
22
24
  capture = case subcommand.to_s
23
25
  when 'shasum', 'search' then true
24
26
  else false
25
27
  end
26
28
 
27
- new(:artifact, subcommand, *args).run(capture: capture)
29
+ new(:artifact, subcommand, *args).run(capture: capture, exception: exception)
28
30
  end
29
31
 
30
- def annotate(body, *args)
31
- new(:annotate, body, *args).run
32
+ def annotate(body, *args, exception: false)
33
+ new(:annotate, body, *args).run(exception: exception)
32
34
  end
33
35
 
34
- def meta_data(subcommand, *args)
36
+ def meta_data(subcommand, *args, exception: false)
35
37
  capture = case subcommand.to_s
36
38
  when 'get', 'keys' then true
37
39
  else false
38
40
  end
39
41
 
40
- new(:'meta-data', subcommand, *args).run(capture: capture)
42
+ new(:'meta-data', subcommand, *args).run(capture: capture, exception: exception)
41
43
  end
42
44
  end
43
45
 
44
46
  COMMANDS.each do |command|
45
47
  define_singleton_method("#{command}!") do |*args|
46
- abort unless public_send(command, *args)
48
+ public_send(command, *args, exception: true)
49
+ rescue CommandFailedError => e
50
+ abort e.message
47
51
  end
48
52
  end
49
53
 
@@ -54,9 +58,17 @@ module Buildkite
54
58
  @args = transform_args(args)
55
59
  end
56
60
 
57
- def run(capture: false)
58
- stdout, _, status = Open3.capture3(*to_a)
59
- capture ? stdout : status.success?
61
+ def run(capture: false, exception: false)
62
+ stdout, stderr, status = Open3.capture3(*to_a)
63
+ if capture
64
+ stdout
65
+ elsif status.success?
66
+ true
67
+ elsif exception
68
+ raise CommandFailedError, "#{stdout}\n#{stderr}"
69
+ else
70
+ false
71
+ end
60
72
  end
61
73
 
62
74
  private
@@ -4,15 +4,36 @@ module Buildkite
4
4
  module Pipelines
5
5
  module Helpers
6
6
  module Retry
7
- def automatic_retry_on(exit_status:, limit:)
7
+ def automatic_retry_on(exit_status: nil, limit: nil, signal_reason: nil)
8
+ raise 'limit must set for `automatic_retry_on`.' unless limit
9
+
10
+ if exit_status.nil? && signal_reason.nil?
11
+ raise 'signal_reason or exit_status must set for `automatic_retry_on`.'
12
+ end
13
+
8
14
  retry_value = get(:retry) || set(:retry, {})
9
15
 
10
16
  unless retry_value[:automatic].is_a?(Array)
11
17
  retry_value[:automatic] = []
12
18
  end
13
19
 
14
- retry_value[:automatic].delete_if { |rule| rule[:exit_status] == exit_status }
15
- retry_value[:automatic].push(exit_status: exit_status, limit: limit)
20
+ automatic_options = { limit: limit }
21
+
22
+ if exit_status && signal_reason
23
+ retry_value[:automatic].delete_if do |rule|
24
+ rule[:exit_status] == exit_status && rule[:signal_reason] == signal_reason
25
+ end
26
+ automatic_options[:exit_status] = exit_status
27
+ automatic_options[:signal_reason] = signal_reason
28
+ elsif exit_status
29
+ retry_value[:automatic].delete_if { |rule| rule[:exit_status] == exit_status }
30
+ automatic_options[:exit_status] = exit_status
31
+ elsif signal_reason
32
+ retry_value[:automatic].delete_if { |rule| rule[:signal_reason] == signal_reason }
33
+ automatic_options[:signal_reason] = signal_reason
34
+ end
35
+
36
+ retry_value[:automatic].push(automatic_options)
16
37
  end
17
38
 
18
39
  def automatic_retry(enabled)
@@ -4,9 +4,9 @@ module Buildkite
4
4
  module Pipelines
5
5
  module Steps
6
6
  class Group < Abstract
7
- attribute :depends_on, append: true
8
- attribute :key
9
7
  attribute :label
8
+ attribute :key
9
+ attribute :depends_on, append: true
10
10
 
11
11
  attr_reader :steps
12
12
 
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: 4.1.0
4
+ version: 4.1.2
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-16 00:00:00.000000000 Z
12
+ date: 2023-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []
177
- rubygems_version: 3.3.26
177
+ rubygems_version: 3.3.13
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: A gem for programmatically creating Buildkite pipelines.