buildkite-builder 3.5.0 → 3.7.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: 64089d229e28dcf07061f4a32178cbf29fc157f2004e03adb84a800f24c2b8fd
4
- data.tar.gz: d4faa31aac7205a07c29ef2766ae3067079d6d72ddb938adfdcec943babd564c
3
+ metadata.gz: 3804d4ee1257c87c370c1be4bf744c531521294c24a19eb48c87f55277e88754
4
+ data.tar.gz: a7d49a4058d7873669aae486848be13ec8a84af758df0f74bf44560fcd686e5b
5
5
  SHA512:
6
- metadata.gz: 67c3325a7b86690c80d771a4cf7738718f1d072481cd23a2b21e9cd1bdb9c9a76b96fc35bb270d09c2ca1e69fbbd7e1d81c8b334a6973e4b148a27ebbf98c504
7
- data.tar.gz: 7f4263163c198d8158fbc93e52dab34369ec51e5957860f4203d602ed6c7e445c018d8cf842584fafbfa2e9d44e0722e0ded99efb754d373bbff96f45bb676c2
6
+ metadata.gz: c7d55f1b56b362778809522dc3d7c42567b19a89192074fd72c9b20261ab7d061e0f3498943f02082548bdb7bd41ae98db485bc09a335938675be2c78491a177
7
+ data.tar.gz: e72473fbeb58287e8c2ec898490666777b54bb7e496faad5f80cc0c923d8bece96891ec6921342bb09191eef50a3a798185db6e710cd3169e507b70dff443836
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.6.0
2
+ * `Buildkite::Pipelines::Command#run` now uses `Open3.capture3` to run system commands, and accepts an optional arg `capture`. When `capture` is true, it returns the stdout of the command. `capture` is true for the meta_data subcommands `get` and `keys` and for the artifact subcommands `shasum` and `search`.
3
+
1
4
  ## 3.5.0
2
5
  * `plugin` registrations now takes an optional default attributes hash as the third argument.
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.5.0
1
+ 3.7.0
@@ -32,16 +32,6 @@ module Buildkite
32
32
  context.logger
33
33
  end
34
34
 
35
- def buildkite
36
- @buildkite ||= begin
37
- unless Buildkite.env
38
- raise 'Must be in Buildkite environment to access the Buildkite API'
39
- end
40
-
41
- Buildkite::Pipelines::Api.new(Buildkite.env.api_token)
42
- end
43
- end
44
-
45
35
  def prepare
46
36
  # Override to provide extra functionality.
47
37
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
4
+
3
5
  module Buildkite
4
6
  module Pipelines
5
7
  class Command
@@ -17,7 +19,12 @@ module Buildkite
17
19
  end
18
20
 
19
21
  def artifact(subcommand, *args)
20
- new(:artifact, subcommand, *args).run
22
+ capture = case subcommand.to_s
23
+ when 'shasum', 'search' then true
24
+ else false
25
+ end
26
+
27
+ new(:artifact, subcommand, *args).run(capture: capture)
21
28
  end
22
29
 
23
30
  def annotate(body, *args)
@@ -25,7 +32,12 @@ module Buildkite
25
32
  end
26
33
 
27
34
  def meta_data(subcommand, *args)
28
- new(:'meta-data', subcommand, *args).run
35
+ capture = case subcommand.to_s
36
+ when 'get', 'keys' then true
37
+ else false
38
+ end
39
+
40
+ new(:'meta-data', subcommand, *args).run(capture: capture)
29
41
  end
30
42
  end
31
43
 
@@ -42,8 +54,9 @@ module Buildkite
42
54
  @args = transform_args(args)
43
55
  end
44
56
 
45
- def run
46
- system(*to_a)
57
+ def run(capture: false)
58
+ stdout, _, status = Open3.capture3(*to_a)
59
+ capture ? stdout : status.success?
47
60
  end
48
61
 
49
62
  private
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Buildkite
4
4
  module Pipelines
5
- autoload :Api, File.expand_path('pipelines/api', __dir__)
6
5
  autoload :Attributes, File.expand_path('pipelines/attributes', __dir__)
7
6
  autoload :Command, File.expand_path('pipelines/command', __dir__)
8
7
  autoload :Helpers, File.expand_path('pipelines/helpers', __dir__)
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.5.0
4
+ version: 3.7.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-10-21 00:00:00.000000000 Z
12
+ date: 2022-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -132,7 +132,6 @@ files:
132
132
  - lib/buildkite/builder/template_manager.rb
133
133
  - lib/buildkite/env.rb
134
134
  - lib/buildkite/pipelines.rb
135
- - lib/buildkite/pipelines/api.rb
136
135
  - lib/buildkite/pipelines/attributes.rb
137
136
  - lib/buildkite/pipelines/command.rb
138
137
  - lib/buildkite/pipelines/helpers.rb
@@ -178,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
177
  - !ruby/object:Gem::Version
179
178
  version: '0'
180
179
  requirements: []
181
- rubygems_version: 3.2.32
180
+ rubygems_version: 3.3.7
182
181
  signing_key:
183
182
  specification_version: 4
184
183
  summary: A gem for programmatically creating Buildkite pipelines.
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
6
-
7
- module Buildkite
8
- module Pipelines
9
- class Api
10
- BASE_URI = URI('https://api.buildkite.com/v2').freeze
11
- URI_PARTS = {
12
- organization: 'organizations',
13
- pipeline: 'pipelines',
14
- pipelines: 'pipelines',
15
- build: 'builds',
16
- builds: 'builds',
17
- access_token: 'access-token',
18
- }.freeze
19
-
20
- def initialize(token)
21
- @token = token
22
- end
23
-
24
- def get_access_token
25
- uri = uri_for(access_token: nil)
26
- JSON.parse(get_request(uri).body)
27
- end
28
-
29
- def list_pipelines(organization)
30
- raise NotImplementedError
31
- end
32
-
33
- def get_pipeline(organization, pipeline)
34
- response = get_request(
35
- uri_for(
36
- organization: organization,
37
- pipeline: pipeline
38
- )
39
- )
40
- if response.is_a?(Net::HTTPSuccess)
41
- JSON.parse(response.body)
42
- end
43
- end
44
-
45
- def create_pipeline(organization, params)
46
- uri = uri_for(
47
- organization: organization,
48
- pipelines: nil
49
- )
50
- JSON.parse(post_request(uri, params).body)
51
- end
52
-
53
- def get_pipeline_builds(organization, pipeline, **params)
54
- uri = uri_for(params.merge(
55
- organization: organization,
56
- pipeline: pipeline,
57
- builds: nil
58
- ))
59
- JSON.parse(get_request(uri).body)
60
- end
61
-
62
- def get_build(organization, pipeline, build)
63
- uri = uri_for(
64
- organization: organization,
65
- pipeline: pipeline,
66
- build: build
67
- )
68
- JSON.parse(get_request(uri).body)
69
- end
70
-
71
- def create_build(organization, pipeline)
72
- raise NotImplementedError
73
- end
74
-
75
- def cancel_build(organization, pipeline, build)
76
- raise NotImplementedError
77
- end
78
-
79
- def rebuild_build(organization, pipeline, build)
80
- raise NotImplementedError
81
- end
82
-
83
- private
84
-
85
- def get_request(uri)
86
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
87
- request = prepare_request(Net::HTTP::Get.new(uri))
88
- http.request(request)
89
- end
90
- end
91
-
92
- def post_request(uri, data)
93
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
94
- request = prepare_request(Net::HTTP::Post.new(uri))
95
- request.content_type = 'application/json'
96
- request.body = data.to_json
97
- http.request(request)
98
- end
99
- end
100
-
101
- def uri_for(options)
102
- uri_parts = URI_PARTS.each_with_object([]) do |(resource, path), parts|
103
- if options.key?(resource)
104
- parts << [path, options.delete(resource)].compact
105
- end
106
- end
107
- uri = URI(uri_parts.flatten.unshift(BASE_URI).join('/'))
108
- uri.query = URI.encode_www_form(options) if options.any?
109
- uri
110
- end
111
-
112
- def prepare_request(request)
113
- request['Authorization'] = "Bearer #{@token}"
114
- request['Accept'] = 'application/json'
115
- request
116
- end
117
- end
118
- end
119
- end