buildkite-builder 4.1.1 → 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: 8d0f3ff0ed7f9f3733ecf88da93150959025b484bdae546237b96a3ace1ac46e
4
- data.tar.gz: 14abc08e2a993a622c937b8822cbdc01b467883bbeca37f598185a7f21293a43
3
+ metadata.gz: 1a02f80263e1373648688276099006c4d2c6870803bb82196cdce5be97d89ad5
4
+ data.tar.gz: bee2180eac619b4bc4931434f12e02d199fd95c82bcf43e9798b96d01f76f263
5
5
  SHA512:
6
- metadata.gz: 9263c2d4f11e8313e79a567a2efe2a5bfeeee06fa3b476763c550f092f6285413bd9a859875e598b457484b870a4a738ee5ac9d90c2fe7334c5856ce755d4891
7
- data.tar.gz: 6d44131cc78e0a56c5aa859419d3e5386bee8b02664b999db93eacccb9f51028250ab80fd358226c4e5f5b5defa26a8ed00aa0a8a9cb9a3304681845462e79ee
6
+ metadata.gz: c8f8028dbc2b311ed71a5dd287d805e8cf417832495172405e2d5556f6535163ab5400a8506c7c9ecd0a32099a0cf7283c32f854f86781c1615284e3032c9319
7
+ data.tar.gz: eda46a592c6f8630e177f539369c3bbf1d619429b32407db7fbf461420592ef9263982dbe4ed4e6f0203baeac8a5a06362aa493e5a6b26680a52f05c904f73f2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.1.1
1
+ 4.1.2
@@ -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)
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.1
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-21 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.