selective-ruby-core 0.2.2-x86_64-darwin → 0.2.4-x86_64-darwin

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: 2b31916fb7c624fac39cd7b3a2ccf05e076c189e96685e1bba20469f2fa5e4fd
4
- data.tar.gz: 909ac8b3216b515a5a2cbeb2481e6bffe035f1482b7cb40bd425cc730a0c3c94
3
+ metadata.gz: bf4ede6530f65732361cb3edca6e3bf1fe1b75702d42460710248e6afd77d042
4
+ data.tar.gz: 8d09d05ec38cc9aea45834835bd98fe6d94f7387d06cfa337d632ba97c68b69d
5
5
  SHA512:
6
- metadata.gz: 9e209155405afc706b36bae7fd1ffbc7bc526096b675ba65416e2129ee3e61b855fb92878badde69630effb01d35425411a9a14329e33123e3c36f2e22b234b7
7
- data.tar.gz: 55a7aafc15597659a88afd9ab4a51db7b7713a7eb47e9290b68c2d4257a13d554c7381d1bdf63c36e07b3d8727d1a47b2b90b1c0e9ea456826453f3ad0358a73
6
+ metadata.gz: 27a5595b47add478a1c99c71f7574a66b6fbe0cf8deafb503bedd48f61302397469658b7f0d9cc71c147668980a50169c48c2e4a3c912afb0a6ed8dab3088429
7
+ data.tar.gz: 5f1a0a6a1644f4193eb2d29eaf820278a7a74b96a0f1c8a49e2b3e7623485379b7f1f207285c145120a97f9dabb69308c4a1bbf64f3b4836102420f016b531a3
data/lib/bin/build_env.sh CHANGED
@@ -31,22 +31,26 @@ elif [ -n "$SEMAPHORE" ]; then
31
31
  pr_title=$SEMAPHORE_GIT_PR_NAME
32
32
  fi
33
33
 
34
+ function escape() {
35
+ echo -n "$1" | sed 's/"/\\"/g'
36
+ }
37
+
34
38
  # Output the JSON
35
39
  cat <<EOF
36
40
  {
37
- "api_key": "$SELECTIVE_API_KEY",
38
- "host": "${SELECTIVE_HOST:-wss://app.selective.ci}",
39
- "platform": "${SELECTIVE_PLATFORM:-$platform}",
40
- "branch": "${SELECTIVE_BRANCH:-$branch}",
41
- "pr_title": "${SELECTIVE_PR_TITLE:-$pr_title}",
42
- "target_branch": "${SELECTIVE_TARGET_BRANCH:-$target_branch}",
43
- "actor": "${SELECTIVE_ACTOR:-$actor}",
44
- "sha": "${SELECTIVE_SHA:-$sha}",
45
- "run_id": "${SELECTIVE_RUN_ID:-$run_id}",
46
- "run_attempt": "${SELECTIVE_RUN_ATTEMPT:-$run_attempt}",
47
- "runner_id": "${SELECTIVE_RUNNER_ID:-$runner_id}",
48
- "commit_message": "$(git log --format=%s -n 1 $sha)",
49
- "committer_name": "$(git show -s --format='%an' -n 1 $sha)",
50
- "committer_email": "$(git show -s --format='%ae' -n 1 $sha)"
41
+ "api_key": "$(escape "${SELECTIVE_API_KEY}")",
42
+ "host": "$(escape "${SELECTIVE_HOST:-wss://app.selective.ci}")",
43
+ "platform": "$(escape "${SELECTIVE_PLATFORM:-$platform}")",
44
+ "branch": "$(escape "${SELECTIVE_BRANCH:-$branch}")",
45
+ "pr_title": "$(escape "${SELECTIVE_PR_TITLE:-$pr_title}")",
46
+ "target_branch": "$(escape "${SELECTIVE_TARGET_BRANCH:-$target_branch}")",
47
+ "actor": "$(escape "${SELECTIVE_ACTOR:-$actor}")",
48
+ "sha": "$(escape "${SELECTIVE_SHA:-$sha}")",
49
+ "run_id": "$(escape "${SELECTIVE_RUN_ID:-$run_id}")",
50
+ "run_attempt": "$(escape "${SELECTIVE_RUN_ATTEMPT:-$run_attempt}")",
51
+ "runner_id": "$(escape "${SELECTIVE_RUNNER_ID:-$runner_id}")",
52
+ "commit_message": "$(escape "$(git log --format=%s -n 1 $sha)")",
53
+ "committer_name": "$(escape "$(git show -s --format='%an' -n 1 $sha)")",
54
+ "committer_email": "$(escape "$(git show -s --format='%ae' -n 1 $sha)")"
51
55
  }
52
56
  EOF
data/lib/bin/transport CHANGED
Binary file
@@ -8,6 +8,7 @@ module Selective
8
8
  class Controller
9
9
  include Helper
10
10
  @@selective_suppress_reporting = false
11
+ @@report_at_finish = {}
11
12
 
12
13
  REQUIRED_CONFIGURATION = {
13
14
  "host" => "SELECTIVE_HOST",
@@ -33,7 +34,7 @@ module Selective
33
34
  handle_termination_signals(transport_pid)
34
35
  wait_for_connectivity
35
36
  run_main_loop
36
- rescue NamedPipe::PipeClosedError
37
+ rescue ConnectionLostError
37
38
  retry!
38
39
  rescue => e
39
40
  with_error_handling { raise e }
@@ -57,12 +58,16 @@ module Selective
57
58
  @@selective_suppress_reporting
58
59
  end
59
60
 
61
+ def self.report_at_finish
62
+ @@report_at_finish
63
+ end
64
+
60
65
  private
61
66
 
62
67
  attr_reader :runner, :pipe, :transport_pid, :retries, :logger, :runner_id, :diff
63
68
 
64
69
  def get_runner_id
65
- runner_id = build_env.delete("runner_id")
70
+ runner_id = build_env["runner_id"]
66
71
  return generate_runner_id if runner_id.nil? || runner_id.empty?
67
72
 
68
73
  runner_id
@@ -90,10 +95,10 @@ module Selective
90
95
  def retry!
91
96
  @retries += 1
92
97
 
93
- with_error_handling { raise "Too many retries" } if retries > 4
98
+ with_error_handling { raise "Too many retries" } if retries > 10
94
99
 
95
- puts("Retrying in #{retries} seconds...")
96
- sleep(retries)
100
+ puts("Retrying in #{retries} seconds...") if debug?
101
+ sleep(retries > 4 ? 4 : retries)
97
102
  kill_transport
98
103
 
99
104
  pipe.reset!
@@ -109,29 +114,30 @@ module Selective
109
114
  end
110
115
 
111
116
  def transport_url(reconnect: false)
112
- @transport_url ||= begin
113
- api_key = build_env.delete("api_key")
114
- host = build_env.delete("host")
115
- run_id = build_env.delete("run_id")
116
- run_attempt = build_env.delete("run_attempt")
117
+ base_transport_url_params[:reconnect] = true if reconnect
118
+ query_string = URI.encode_www_form(base_transport_url_params)
119
+ "#{build_env["host"]}/transport/websocket?#{query_string}"
120
+ end
121
+
122
+ def base_transport_url_params
123
+ @base_transport_url_params ||= begin
124
+ api_key = build_env["api_key"]
125
+ run_id = build_env["run_id"]
126
+ run_attempt = build_env["run_attempt"]
117
127
 
118
- params = {
128
+ metadata = build_env.reject { |k,v| %w(host runner_id api_key run_id run_attempt).include?(k) }
129
+
130
+ {
131
+ "api_key" => api_key,
119
132
  "run_id" => run_id,
120
133
  "run_attempt" => run_attempt,
121
- "api_key" => api_key,
122
134
  "runner_id" => runner_id,
123
135
  "language" => "ruby",
124
136
  "core_version" => Selective::Ruby::Core::VERSION,
125
137
  "framework" => runner.framework,
126
138
  "framework_version" => runner.framework_version,
127
139
  "framework_wrapper_version" => runner.wrapper_version,
128
- }.merge(metadata: build_env.to_json)
129
-
130
- prams[:reconnect] = true if reconnect
131
-
132
- query_string = URI.encode_www_form(params)
133
-
134
- "#{host}/transport/websocket?#{query_string}"
140
+ }.merge(metadata: metadata.to_json)
135
141
  end
136
142
  end
137
143
 
@@ -224,7 +230,7 @@ module Selective
224
230
 
225
231
  sleep(1)
226
232
  end
227
- rescue NamedPipe::PipeClosedError, IOError
233
+ rescue ConnectionLostError, IOError
228
234
  # If the pipe is close, move straight to killing
229
235
  # it forcefully.
230
236
  end
@@ -270,8 +276,11 @@ module Selective
270
276
  runner.run_test_cases(data[:test_case_ids])
271
277
  end
272
278
 
279
+ # Todo: Rename this command to match the method name
280
+ # on the runner wrapper. We should do something similar
281
+ # to normalize handle_print_notice and handle_print_message
273
282
  def handle_remove_failed_test_case_result(data)
274
- runner.remove_failed_test_case_result(data[:test_case_id])
283
+ runner.remove_test_case_result(data[:test_case_id])
275
284
  end
276
285
 
277
286
  def handle_print_message(data)
@@ -281,7 +290,13 @@ module Selective
281
290
  def handle_close(data)
282
291
  exit_status = data[:exit_status]
283
292
  self.class.restore_reporting!
284
- with_error_handling { runner.finish } unless exit_status.is_a?(Integer)
293
+
294
+ with_error_handling do
295
+ Selective::Ruby::Core::Controller.report_at_finish[:connection_retries] = @retries
296
+ write({type: "report_at_finish", data: Selective::Ruby::Core::Controller.report_at_finish})
297
+
298
+ runner.finish unless exit_status.is_a?(Integer)
299
+ end
285
300
 
286
301
  kill_transport
287
302
  pipe.delete_pipes
@@ -9,7 +9,7 @@ module Selective
9
9
  FILE_CORRELATION_COLLECTOR_PATH = File.join(ROOT_GEM_PATH, "lib", "bin", "file_correlation_collector.sh")
10
10
 
11
11
  def initialize(diff, num_commits, target_branch)
12
- @diff = diff
12
+ @diff = diff.reject {|f| f =~ /^spec\// }
13
13
  @num_commits = num_commits
14
14
  @target_branch = target_branch
15
15
  end
@@ -2,8 +2,6 @@ module Selective
2
2
  module Ruby
3
3
  module Core
4
4
  class NamedPipe
5
- class PipeClosedError < StandardError; end
6
-
7
5
  attr_reader :read_pipe_path, :write_pipe_path
8
6
 
9
7
  def initialize(read_pipe_path, write_pipe_path, skip_reset: false)
@@ -44,7 +42,7 @@ module Selective
44
42
  write_pipe.write("\n")
45
43
  write_pipe.flush
46
44
  rescue Errno::EPIPE
47
- raise PipeClosedError
45
+ raise ConnectionLostError
48
46
  end
49
47
  end
50
48
 
@@ -54,7 +52,7 @@ module Selective
54
52
  message = read_pipe.gets.chomp
55
53
  rescue NoMethodError => e
56
54
  if e.name == :chomp
57
- raise PipeClosedError
55
+ raise ConnectionLostError
58
56
  else
59
57
  raise e
60
58
  end
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.2.2"
6
+ VERSION = "0.2.4"
7
7
  end
8
8
  end
9
9
  end
@@ -14,6 +14,7 @@ module Selective
14
14
  module Ruby
15
15
  module Core
16
16
  class Error < StandardError; end
17
+ class ConnectionLostError < StandardError; end
17
18
 
18
19
  ROOT_GEM_PATH = Gem.loaded_specs["selective-ruby-core"].full_gem_path
19
20
 
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.2.2
4
+ version: 0.2.4
5
5
  platform: x86_64-darwin
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-26 00:00:00.000000000 Z
12
+ date: 2024-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.4.10
74
+ rubygems_version: 3.5.3
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Selective Ruby Client Core