selective-ruby-core 0.1.4-x86_64-darwin → 0.1.6-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bin/build_env.sh +14 -7
- data/lib/selective/ruby/core/controller.rb +58 -59
- data/lib/selective/ruby/core/version.rb +1 -1
- data/lib/selective-ruby-core.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52bc426a0bd0a0f89a42565923fe7a56b39fe5e3ccb85818f6fbf5d80a9db930
|
4
|
+
data.tar.gz: 7659c45d74078a348ecdef940df164a46110dbdd4275973a8863c233d108b0a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a49e387e6cdf21d20cdc35b7bc63726f0bcd57433e5d2533552fa597c38f095c03e09ae346e999925dcd9a22bd9340d423c5e0fadb70daaf3239a771a3f7f20f
|
7
|
+
data.tar.gz: 158a9217e73199e77c260467c8d7c3ec07b2e998bed8ba7f4ab651906ddb4a6ff2b67b1209b6803708644fe602ecaa1f10e66f01d97af9c6db597665f35abd7a
|
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
|
-
|
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
|
-
|
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": "$
|
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": "$
|
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(
|
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
|
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
|
-
|
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
|
-
|
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 = `#{
|
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(
|
133
|
-
|
134
|
-
|
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,
|
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
|
@@ -156,7 +167,7 @@ module Selective
|
|
156
167
|
@connectivity = false
|
157
168
|
|
158
169
|
Thread.new do
|
159
|
-
sleep(
|
170
|
+
sleep(30)
|
160
171
|
unless @connectivity
|
161
172
|
puts "Transport process failed to start. Exiting..."
|
162
173
|
kill_transport
|
@@ -211,39 +222,23 @@ module Selective
|
|
211
222
|
# Process already gone noop
|
212
223
|
end
|
213
224
|
|
214
|
-
def handle_command(
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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
|
-
|
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(
|
255
|
-
runner.run_test_cases(
|
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
|
data/lib/selective-ruby-core.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
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")
|
8
|
+
loader.ignore("#{__dir__}/selective/ruby/core/version.rb")
|
7
9
|
loader.setup
|
8
10
|
|
9
11
|
module Selective
|
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.
|
4
|
+
version: 0.1.6
|
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:
|
12
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|