buildkite-builder 4.4.0 → 4.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86f89af006c84e916bc75c42fec68f5e308544592b49dcee1b8e0cdde4029bf6
4
- data.tar.gz: ce1c87417d57468896e8f15be3e3678de6c920625b3b070c3b84c3c553ae0c59
3
+ metadata.gz: 4bf8325879836987ca1d33d9822e1c2aaf315843c7ee2b99e5791378a893c767
4
+ data.tar.gz: 2e9edbde3a0db277878a8f307ef0e1975a4dde99c396e87a3ecb1b9b2673b405
5
5
  SHA512:
6
- metadata.gz: bb99d435663020e86296e11f330f5d0f58832486a89febac1b4e199ae48a2a463e2be4906b226f9d654a46b49fc091c33d0481e56f7949c28004db7e17917958
7
- data.tar.gz: 2943c7b52a2e1ef61f9325758255fdd29fe037b3ac658db2ffd298a2ff2ecc2aa544c5aba7b16a2135e7abb7814166feb5608c064e98b2a4077a825f062dd54c
6
+ metadata.gz: bb4cf5652a702e0d030350db16c0447d72cd2000a6cb32fa4f1a89d00c38cc0e5820661ca1fb67de8abe4a56b177172a4a806a4d05ff954744a01dcd2ec56c32
7
+ data.tar.gz: c04110b0ca0f550a4a2be480f9aecde71566358fb9d638a4a0c96d1c503c3de6272a75b78083bb21b60d81a3fc12d4440c80445e5a0f9d41bbae5ea4a130ee30
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 4.6.0
2
+ * Remove `capture` concept on `Buildkite::Pipelines::Command#run` and replaced with `Buildkite::Pipelines::Command::Result` object to represent `Open3.capture3` result.
3
+
4
+ ### 4.5.0
5
+ * Do not upload `pipeline.yml` when steps is empty.
6
+
1
7
  ### 4.4.0
2
8
  * Fix multiple arguments for `depends_on`.
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.4.0
1
+ 4.6.0
@@ -17,7 +17,7 @@ module Buildkite
17
17
  # variables to be set. It also uploads the pipeline to Buildkite.
18
18
  log.info "+++ 🧰 #{'Buildkite Builder'.color(:springgreen)} v#{Buildkite::Builder.version} ─ #{relative_pipeline_path.to_s.yellow}"
19
19
 
20
- if Buildkite::Pipelines::Command.meta_data(:exists, Builder.meta_data.fetch(:job))
20
+ if Buildkite::Pipelines::Command.meta_data(:exists, Builder.meta_data.fetch(:job)).success?
21
21
  log.info "Pipeline already uploaded in #{Buildkite.env.step_id} step".color(:dimgray)
22
22
  else
23
23
  Pipeline.new(pipeline_path, logger: log).upload
@@ -45,20 +45,28 @@ module Buildkite
45
45
 
46
46
  upload_artifacts
47
47
 
48
- # Upload the pipeline.
49
- Tempfile.create(['pipeline', '.yml']) do |file|
50
- file.sync = true
51
- file.write(contents)
52
-
53
- logger.info "+++ :pipeline: Uploading pipeline"
54
- unless Buildkite::Pipelines::Command.pipeline(:upload, file.path)
55
- logger.info "Pipeline upload failed, saving as artifact…"
56
- Buildkite::Pipelines::Command.artifact!(:upload, file.path)
57
- abort
48
+ if data.steps.empty?
49
+ logger.info "+++ :pipeline: No steps defined, skipping pipeline upload"
50
+ else
51
+ # Upload the pipeline.
52
+ Tempfile.create(['pipeline', '.yml']) do |file|
53
+ file.sync = true
54
+ file.write(contents)
55
+
56
+ logger.info "+++ :pipeline: Uploading pipeline"
57
+
58
+ result = Buildkite::Pipelines::Command.pipeline(:upload, file.path)
59
+
60
+ unless result.success?
61
+ logger.info "Pipeline upload failed with #{result.stderr}, saving as artifact…"
62
+ Buildkite::Pipelines::Command.artifact!(:upload, file.path)
63
+ abort
64
+ end
58
65
  end
59
- logger.info "+++ :toolbox: Setting job meta-data to #{Buildkite.env.job_id.color(:yellow)}"
60
- Buildkite::Pipelines::Command.meta_data!(:set, Builder.meta_data.fetch(:job), Buildkite.env.step_id)
61
66
  end
67
+
68
+ logger.info "+++ :toolbox: Setting job meta-data to #{Buildkite.env.job_id.color(:yellow)}"
69
+ Buildkite::Pipelines::Command.meta_data!(:set, Builder.meta_data.fetch(:job), Buildkite.env.step_id)
62
70
  end
63
71
 
64
72
  def to_h
@@ -55,6 +55,10 @@ module Buildkite
55
55
  def to_definition
56
56
  @steps.map(&:to_h)
57
57
  end
58
+
59
+ def empty?
60
+ @steps.empty? || (@steps.all? { |step| step.is_a?(Pipelines::Steps::Group) && step.steps.empty? })
61
+ end
58
62
  end
59
63
  end
60
64
  end
@@ -7,6 +7,23 @@ module Buildkite
7
7
  class Command
8
8
  class CommandFailedError < StandardError; end
9
9
 
10
+ class Result
11
+ attr_reader :stdout, :stderr
12
+ def initialize(stdout, stderr, status)
13
+ @stdout = stdout.strip
14
+ @stderr = stderr.strip
15
+ @status = status
16
+ end
17
+
18
+ def success?
19
+ @status.success?
20
+ end
21
+
22
+ def output
23
+ @output ||= "#{stdout}\n#{stderr}".strip
24
+ end
25
+ end
26
+
10
27
  BIN_PATH = 'buildkite-agent'
11
28
  COMMANDS = %w(
12
29
  pipeline
@@ -21,12 +38,12 @@ module Buildkite
21
38
  end
22
39
 
23
40
  def artifact(subcommand, *args, exception: false)
24
- capture = case subcommand.to_s
25
- when 'shasum', 'search' then true
26
- else false
27
- end
41
+ result = new(:artifact, subcommand, *args).run(exception: exception)
28
42
 
29
- new(:artifact, subcommand, *args).run(capture: capture, exception: exception)
43
+ case subcommand.to_s
44
+ when 'shasum', 'search' then result.output
45
+ else result
46
+ end
30
47
  end
31
48
 
32
49
  def annotate(body, *args, exception: false)
@@ -34,12 +51,12 @@ module Buildkite
34
51
  end
35
52
 
36
53
  def meta_data(subcommand, *args, exception: false)
37
- capture = case subcommand.to_s
38
- when 'get', 'keys' then true
39
- else false
40
- end
54
+ result = new(:'meta-data', subcommand, *args).run(exception: exception)
41
55
 
42
- new(:'meta-data', subcommand, *args).run(capture: capture, exception: exception)
56
+ case subcommand.to_s
57
+ when 'get', 'keys' then result.output
58
+ else result
59
+ end
43
60
  end
44
61
  end
45
62
 
@@ -58,16 +75,14 @@ module Buildkite
58
75
  @args = transform_args(args)
59
76
  end
60
77
 
61
- def run(capture: false, exception: false)
78
+ def run(exception: false)
62
79
  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}"
80
+ result = Result.new(stdout, stderr, status)
81
+
82
+ if !result.success? && exception
83
+ raise CommandFailedError, "#{result.output}"
69
84
  else
70
- false
85
+ result
71
86
  end
72
87
  end
73
88
 
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.4.0
4
+ version: 4.6.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: 2023-09-27 00:00:00.000000000 Z
12
+ date: 2023-12-12 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.