selective-ruby-core 0.1.7-aarch64-linux → 0.1.9-aarch64-linux

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: cda7bb49825b1322ab9bb0d3bc643744bf79dc70c7a8a611fd4cc39cba7ca494
4
- data.tar.gz: 596d3053cb1de84eba9ca0a1488600fc559c647fe963c882cfd62b6b34b60686
3
+ metadata.gz: d396e26c8bae6e3ace92a0cb027627ee691e818bec433ea1af28dc108b48afc4
4
+ data.tar.gz: cfcab6ed9eff376aceb940ea4ef7e5ece1353d27aac35254282ab38598cf6779
5
5
  SHA512:
6
- metadata.gz: 72ed3aba011eafbb171074eff2681ec2003144de42f2cdfdf86299604a88500d6bc510b849664befaab8a4d5b60e60a7168de64c271186bce58ba793c28d451f
7
- data.tar.gz: 685d9c77788edc0d1e1b4f2b923982989fdc347fa7710b503b5a3f9beae4238ec3810df37c4491d53ef002d4eaf70502978011ce6b11641a5261f80c546da92b
6
+ metadata.gz: d1f10139bdd46cd2dc5f05e72754471b01d8e0626b92a4da5a6cbd1c83e180eec6e58899860ecda80a2f4a8d0a499c85ac17193e943d73aef9e701667ae96508
7
+ data.tar.gz: 66fa3787af219e72ad55b0a2fb625c01d76867cbaa44fac86fd7699c2c273ae0bc60911ea0246fa22af7bcf6755e4ecf550c4f28409382b9bd0f983f7ef47968
data/lib/bin/build_env.sh CHANGED
@@ -33,6 +33,8 @@ fi
33
33
  # Output the JSON
34
34
  cat <<EOF
35
35
  {
36
+ "api_key": "$SELECTIVE_API_KEY",
37
+ "host": "${SELECTIVE_HOST:-wss://app.selective.ci}",
36
38
  "platform": "$platform",
37
39
  "branch": "$branch",
38
40
  "pr_title": "$SELECTIVE_PR_TITLE",
@@ -9,6 +9,14 @@ module Selective
9
9
  include Helper
10
10
  @@selective_suppress_reporting = false
11
11
 
12
+ REQUIRED_CONFIGURATION = {
13
+ "host" => "SELECTIVE_HOST",
14
+ "api_key" => "SELECTIVE_API_KEY",
15
+ "platform" => "SELECTIVE_PLATFORM",
16
+ "run_id" => "SELECTIVE_RUN_ID",
17
+ "branch" => "SELECTIVE_BRANCH"
18
+ }.freeze
19
+
12
20
  def initialize(runner, debug: false, log: false)
13
21
  @debug = debug
14
22
  @runner = runner
@@ -101,12 +109,8 @@ module Selective
101
109
 
102
110
  def transport_url(reconnect: false)
103
111
  @transport_url ||= begin
104
- api_key = ENV.fetch("SELECTIVE_API_KEY")
105
- host = ENV.fetch("SELECTIVE_HOST", "wss://app.selective.ci")
106
-
107
- # Validate that host is a valid websocket url(starts with ws:// or wss://)
108
- raise "Invalid host: #{host}" unless host.match?(/^wss?:\/\//)
109
-
112
+ api_key = build_env.delete("api_key")
113
+ host = build_env.delete("host")
110
114
  run_id = build_env.delete("run_id")
111
115
  run_attempt = build_env.delete("run_attempt")
112
116
  run_attempt = SecureRandom.uuid if run_attempt.nil? || run_attempt.empty?
@@ -134,7 +138,20 @@ module Selective
134
138
  def build_env
135
139
  @build_env ||= begin
136
140
  result = `#{File.join(ROOT_GEM_PATH, "lib", "bin", "build_env.sh")}`
137
- JSON.parse(result)
141
+ JSON.parse(result).tap do |env|
142
+ validate_build_env(env)
143
+ end
144
+ end
145
+ end
146
+
147
+ def validate_build_env(env)
148
+ missing = REQUIRED_CONFIGURATION.each_with_object([]) do |(key, env_var), arry|
149
+ arry << env_var if env[key].nil? || env[key].empty?
150
+ end
151
+
152
+ with_error_handling do
153
+ raise "Missing required environment variables: #{missing.join(", ")}" unless missing.empty?
154
+ raise "Invalid host: #{env['host']}" unless env['host'].match?(/^wss?:\/\//)
138
155
  end
139
156
  end
140
157
 
@@ -220,9 +237,11 @@ module Selective
220
237
  end
221
238
 
222
239
  def handle_command(data)
223
- send("handle_#{data[:command]}", data)
224
- rescue NoMethodError
225
- raise "Unknown command received: #{data[:command]}" if debug?
240
+ if respond_to? "handle_#{data[:command]}", true
241
+ send("handle_#{data[:command]}", data)
242
+ else
243
+ raise "Unknown command received: #{data[:command]}" if debug?
244
+ end
226
245
  end
227
246
 
228
247
  def handle_print_notice(data)
@@ -262,7 +281,7 @@ module Selective
262
281
  def handle_close(data)
263
282
  exit_status = data[:exit_status]
264
283
  self.class.restore_reporting!
265
- runner.finish unless exit_status.is_a?(Integer)
284
+ with_error_handling { runner.finish } unless exit_status.is_a?(Integer)
266
285
 
267
286
  kill_transport
268
287
  pipe.delete_pipes
@@ -291,12 +310,12 @@ module Selective
291
310
 
292
311
  def get_diff(num_commits)
293
312
  target_branch = build_env["target_branch"]
294
- return [] if target_branch.nil? || target_branch.empty?
313
+ return if target_branch.nil? || target_branch.empty?
295
314
 
296
315
  Open3.capture2e("git fetch origin #{target_branch} --depth=#{num_commits}").then do |output, status|
297
316
  unless status.success?
298
317
  print_warning "Selective was unable to fetch the target branch. This may result in a sub-optimal test order. If the issue persists, please contact support. The output was:\n\n#{output}"
299
- return []
318
+ return
300
319
  end
301
320
  end
302
321
 
@@ -305,7 +324,7 @@ module Selective
305
324
  output.split("\n")
306
325
  else
307
326
  print_warning "Selective was unable to diff with the target branch. This may result in a sub-optimal test order. If the issue persists, please contact support. The output was:\n\n#{output}"
308
- []
327
+ nil
309
328
  end
310
329
  end
311
330
  end
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.1.7"
6
+ VERSION = "0.1.9"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selective-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Benjamin Wood
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-01-05 00:00:00.000000000 Z
12
+ date: 2024-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk