selective-ruby-core 0.1.5-x86_64-linux → 0.1.6-x86_64-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: ced267905bdcf1596a248cdcd2018cd2e628422e2e27aec445311b5d9afd4857
4
- data.tar.gz: f4fbeb39edca06a95e3bf982f7b28c612a4d04d0165556ec341aef304eeb5718
3
+ metadata.gz: 0ec7acf96ff854b3c63a2c89560440378444ec9544694bb4c2107b456c067bcb
4
+ data.tar.gz: c607a7497f234d12f5d7d5011e125a9734f31e0a8ef0070767149bb7dc48a059
5
5
  SHA512:
6
- metadata.gz: 937a82d41f7b323f925d7a5a761a7045617decf18073fd1aedd482a0c613f24adbbbff3ff53e2b2b068d584cfc7da1071f1b101378a4bbb3575a2f625904d58c
7
- data.tar.gz: e93d8037c5af50b1d61700b68dea98d368b56db507480831b5b0be4b704b7e2684614571ef9d789f4c04409464e94b965db1676127a8e7368c0fc0e78aa3b1a9
6
+ metadata.gz: 3c653ea2a4a1cf52ff46e27715619fa70ff20d26fa6f3b363486fef7832f25140a033475af9050d8da912cf5c0e10e69501bb1f040b1766e999ccc0527d7c99c
7
+ data.tar.gz: 86060d98bb070045ba93ebc1d9cd2949d5d5c5cf0f09a99598e732a1c610164f3a9548d69a2d965e90d360d31255b13567f1fbf10e3ac2e8ef922474d046ddd0
data/lib/bin/build_env.sh CHANGED
@@ -2,26 +2,32 @@
2
2
 
3
3
  # Detect the platform (only GitHub Actions in this case)
4
4
  if [ -n "$GITHUB_ACTIONS" ]; then
5
- # Get environment variables
6
5
  platform=github_actions
7
6
  branch=${SELECTIVE_BRANCH:-${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}}
8
- pr_title=$SELECTIVE_PR_TITLE
9
7
  target_branch=${SELECTIVE_TARGET_BRANCH:-$GITHUB_BASE_REF}
10
8
  actor=$GITHUB_ACTOR
11
9
  sha=${SELECTIVE_SHA:-$GITHUB_SHA}
12
10
  run_id=${SELECTIVE_RUN_ID:-$GITHUB_RUN_ID}
13
11
  run_attempt=${SELECTIVE_RUN_ATTEMPT:-$GITHUB_RUN_ATTEMPT}
14
- commit_message=$(git log --format=%s -n 1 $sha)
12
+ runner_id=$SELECTIVE_RUNNER_ID
13
+ elif [ -n "$CIRCLECI" ]; then
14
+ platform=circleci
15
+ branch=${SELECTIVE_BRANCH:-$CIRCLE_BRANCH}
16
+ target_branch=$SELECTIVE_TARGET_BRANCH
17
+ actor=${SELECTIVE_ACTOR:-${CIRCLE_USERNAME:-$CIRCLE_PR_USERNAME}}
18
+ sha=${SELECTIVE_SHA:-$CIRCLE_SHA1}
19
+ run_id=$SELECTIVE_RUN_ID
20
+ run_attempt=${SELECTIVE_RUN_ATTEMPT:-$CIRCLE_BUILD_NUM}
21
+ runner_id=${SELECTIVE_RUNNER_ID:-$CIRCLE_NODE_INDEX}
15
22
  else
16
23
  platform=$SELECTIVE_PLATFORM
17
24
  branch=$SELECTIVE_BRANCH
18
- pr_title=$SELECTIVE_PR_TITLE
19
25
  target_branch=$SELECTIVE_TARGET_BRANCH
20
26
  actor=$SELECTIVE_ACTOR
21
27
  sha=$SELECTIVE_SHA
22
28
  run_id=$SELECTIVE_RUN_ID
23
29
  run_attempt=$SELECTIVE_RUN_ATTEMPT
24
- commit_message=$(git log --format=%s -n 1 $sha)
30
+ runner_id=$SELECTIVE_RUNNER_ID
25
31
  fi
26
32
 
27
33
  # Output the JSON
@@ -29,12 +35,13 @@ cat <<EOF
29
35
  {
30
36
  "platform": "$platform",
31
37
  "branch": "$branch",
32
- "pr_title": "$pr_title",
38
+ "pr_title": "$SELECTIVE_PR_TITLE",
33
39
  "target_branch": "$target_branch",
34
40
  "actor": "$actor",
35
41
  "sha": "$sha",
36
42
  "run_id": "$run_id",
37
43
  "run_attempt": "$run_attempt",
38
- "commit_message": "$commit_message"
44
+ "commit_message": "$(git log --format=%s -n 1 $sha)",
45
+ "runner_id": "$runner_id"
39
46
  }
40
47
  EOF
@@ -14,13 +14,13 @@ module Selective
14
14
  @debug = debug
15
15
  @runner = runner
16
16
  @retries = 0
17
- @runner_id = safe_filename(ENV.fetch("SELECTIVE_RUNNER_ID", generate_runner_id))
17
+ @runner_id = safe_filename(get_runner_id)
18
18
  @logger = init_logger(log)
19
19
  end
20
20
 
21
21
  def start(reconnect: false)
22
22
  @pipe = NamedPipe.new("/tmp/#{runner_id}_2", "/tmp/#{runner_id}_1")
23
- @transport_pid = spawn_transport_process(reconnect ? transport_url + "&reconnect=true" : transport_url)
23
+ @transport_pid = spawn_transport_process(reconnect: reconnect)
24
24
 
25
25
  handle_termination_signals(transport_pid)
26
26
  wait_for_connectivity
@@ -53,7 +53,14 @@ module Selective
53
53
 
54
54
  attr_reader :runner, :pipe, :transport_pid, :retries, :logger, :runner_id
55
55
 
56
- BUILD_ENV_SCRIPT_PATH = "../../../bin/build_env.sh".freeze
56
+ ROOT_GEM_PATH = Gem.loaded_specs["selective-ruby-core"].full_gem_path
57
+
58
+ def get_runner_id
59
+ runner_id = build_env.delete("runner_id")
60
+ return generate_runner_id if runner_id.nil? || runner_id.empty?
61
+
62
+ runner_id
63
+ end
57
64
 
58
65
  def init_logger(enabled)
59
66
  if enabled
@@ -70,9 +77,7 @@ module Selective
70
77
  response = JSON.parse(message, symbolize_names: true)
71
78
 
72
79
  @logger.info("Received Command: #{response}")
73
- next if handle_command(response)
74
-
75
- break
80
+ break if handle_command(response) == :break
76
81
  end
77
82
  end
78
83
 
@@ -97,7 +102,7 @@ module Selective
97
102
  "selgen-#{SecureRandom.hex(4)}"
98
103
  end
99
104
 
100
- def transport_url
105
+ def transport_url(reconnect: false)
101
106
  @transport_url ||= begin
102
107
  api_key = ENV.fetch("SELECTIVE_API_KEY")
103
108
  host = ENV.fetch("SELECTIVE_HOST", "wss://app.selective.ci")
@@ -113,9 +118,16 @@ module Selective
113
118
  "run_id" => run_id,
114
119
  "run_attempt" => run_attempt,
115
120
  "api_key" => api_key,
116
- "runner_id" => runner_id
121
+ "runner_id" => runner_id,
122
+ "language" => "ruby",
123
+ "core_version" => Selective::Ruby::Core::VERSION,
124
+ "framework" => runner.framework,
125
+ "framework_version" => runner.framework_version,
126
+ "framework_wrapper_version" => runner.wrapper_version,
117
127
  }.merge(metadata: build_env.to_json)
118
128
 
129
+ prams[:reconnect] = true if reconnect
130
+
119
131
  query_string = URI.encode_www_form(params)
120
132
 
121
133
  "#{host}/transport/websocket?#{query_string}"
@@ -124,15 +136,14 @@ module Selective
124
136
 
125
137
  def build_env
126
138
  @build_env ||= begin
127
- result = `#{Pathname.new(__dir__) + BUILD_ENV_SCRIPT_PATH}`
139
+ result = `#{File.join(ROOT_GEM_PATH, "lib", "bin", "build_env.sh")}`
128
140
  JSON.parse(result)
129
141
  end
130
142
  end
131
143
 
132
- def spawn_transport_process(url)
133
- root_path = Gem.loaded_specs["selective-ruby-core"].full_gem_path
134
- transport_path = File.join(root_path, "lib", "bin", "transport")
135
- get_transport_path = File.join(root_path, "bin", "get_transport")
144
+ def spawn_transport_process(reconnect: false)
145
+ transport_path = File.join(ROOT_GEM_PATH, "lib", "bin", "transport")
146
+ get_transport_path = File.join(ROOT_GEM_PATH, "bin", "get_transport")
136
147
 
137
148
  # The get_transport script is not released with the gem, so this
138
149
  # code is intended for development/CI purposes.
@@ -147,7 +158,7 @@ module Selective
147
158
  end
148
159
  end
149
160
 
150
- Process.spawn(transport_path, url, runner_id).tap do |pid|
161
+ Process.spawn(transport_path, transport_url(reconnect: reconnect), runner_id).tap do |pid|
151
162
  Process.detach(pid)
152
163
  end
153
164
  end
@@ -211,39 +222,23 @@ module Selective
211
222
  # Process already gone noop
212
223
  end
213
224
 
214
- def handle_command(response)
215
- case response[:command]
216
- when "print_notice"
217
- print_notice(response[:message])
218
- when "test_manifest"
219
- handle_test_manifest
220
- when "run_test_cases"
221
- handle_run_test_cases(response[:test_case_ids])
222
- when "remove_failed_test_case_result"
223
- handle_remove_failed_test_case_result(response[:test_case_id])
224
- when "reconnect"
225
- handle_reconnect
226
- when "print_message"
227
- handle_print_message(response[:message])
228
- when "close"
229
- handle_close(response[:exit_status])
230
- # This return is here for the sake of test where
231
- # we cannot exit but we need to break the loop
232
- return false
233
- else
234
- raise "Unknown command received: #{response[:command]}" if debug?
235
- end
225
+ def handle_command(data)
226
+ send("handle_#{data[:command]}", data)
227
+ rescue NoMethodError
228
+ raise "Unknown command received: #{data[:command]}" if debug?
229
+ end
236
230
 
237
- true
231
+ def handle_print_notice(data)
232
+ print_notice(data[:message])
238
233
  end
239
234
 
240
- def handle_reconnect
235
+ def handle_reconnect(_data)
241
236
  kill_transport
242
237
  pipe.reset!
243
238
  start(reconnect: true)
244
239
  end
245
240
 
246
- def handle_test_manifest
241
+ def handle_test_manifest(_data)
247
242
  self.class.restore_reporting!
248
243
  @logger.info("Sending Response: test_manifest")
249
244
  data = {test_cases: runner.manifest["examples"]}
@@ -251,8 +246,29 @@ module Selective
251
246
  write({type: "test_manifest", data: data})
252
247
  end
253
248
 
254
- def handle_run_test_cases(test_cases)
255
- runner.run_test_cases(test_cases, method(:test_case_callback))
249
+ def handle_run_test_cases(data)
250
+ runner.run_test_cases(data[:test_case_ids], method(:test_case_callback))
251
+ end
252
+
253
+ def handle_remove_failed_test_case_result(data)
254
+ runner.remove_failed_test_case_result(data[:test_case_id])
255
+ end
256
+
257
+ def handle_print_message(data)
258
+ print_warning(data[:message])
259
+ end
260
+
261
+ def handle_close(data)
262
+ exit_status = data[:exit_status]
263
+ self.class.restore_reporting!
264
+ runner.finish unless exit_status.is_a?(Integer)
265
+
266
+ kill_transport
267
+ pipe.delete_pipes
268
+ exit(exit_status || runner.exit_status)
269
+ # This :break is here for the sake of test where
270
+ # we cannot exit but we need to break the loop
271
+ :break
256
272
  end
257
273
 
258
274
  def test_case_callback(test_case)
@@ -260,10 +276,6 @@ module Selective
260
276
  write({type: "test_case_result", data: test_case})
261
277
  end
262
278
 
263
- def handle_remove_failed_test_case_result(test_case_id)
264
- runner.remove_failed_test_case_result(test_case_id)
265
- end
266
-
267
279
  def modified_test_files
268
280
  @modified_test_files ||= begin
269
281
  target_branch = build_env["target_branch"]
@@ -279,19 +291,6 @@ module Selective
279
291
  end
280
292
  end
281
293
 
282
- def handle_print_message(message)
283
- print_warning(message)
284
- end
285
-
286
- def handle_close(exit_status = nil)
287
- self.class.restore_reporting!
288
- runner.finish unless exit_status.is_a?(Integer)
289
-
290
- kill_transport
291
- pipe.delete_pipes
292
- exit(exit_status || runner.exit_status)
293
- end
294
-
295
294
  def debug?
296
295
  @debug
297
296
  end
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.1.5"
6
+ VERSION = "0.1.6"
7
7
  end
8
8
  end
9
9
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "zeitwerk"
4
+ require "#{__dir__}/selective/ruby/core/version"
4
5
 
5
6
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
6
7
  loader.ignore("#{__dir__}/selective-ruby-core.rb")
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.5
4
+ version: 0.1.6
5
5
  platform: x86_64-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: 2023-12-08 00:00:00.000000000 Z
12
+ date: 2024-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk