selective-ruby-core 0.1.2-aarch64-linux → 0.1.4-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: f46c8813512297c86dcc7d42a197c19c69261610793c6476b0ef863e94eac062
4
- data.tar.gz: 59b7700e822f4810a468013ac74701976bcdc09426b718b35bc4350fdde06f14
3
+ metadata.gz: b5500d7971e466047c33f3ed28463a5662b330d90cb3c77812a26155de248319
4
+ data.tar.gz: f391897d219fb94dc0653ad86b1add32a0e7e973dd68fedee18aeaaabcf0081e
5
5
  SHA512:
6
- metadata.gz: 87c2116863c1db55e887569178d8c5b109ee4c50fd9b64413410e9a274da99999ff0756da57b22d80a9ab019761fedc6d53231f878d5eca3f4a52ef1b9b5385f
7
- data.tar.gz: 7e78f5ee5c42ed2d92cb76a2a38225703b3d13d8cb4b2439b117baaf5319933c94139634cde9fde5bab49fbac50b9c369916397f0cdf9ca2005da9a458013c06
6
+ metadata.gz: 65ebb5f6917cd574a8d089b88db70aed8ab9113a144b4895a325947f26bf158ad6f82bd3d18d185932b3851196bc7b292cfad217040c27c9b8c399a65f87a7ef
7
+ data.tar.gz: da6944fa1661503dbf9b341e0f35d568778e38c0bc879ce48aa977f4e21a757abc69c9986796551f43a423a3faac194922631bce097f5a668686d90a60e8f43a
data/lib/bin/build_env.sh CHANGED
@@ -4,11 +4,13 @@
4
4
  if [ -n "$GITHUB_ACTIONS" ]; then
5
5
  # Get environment variables
6
6
  platform=github_actions
7
- branch=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}
7
+ branch=${SELECTIVE_BRANCH:-${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}}
8
8
  pr_title=$SELECTIVE_PR_TITLE
9
- target_branch=${GITHUB_BASE_REF}
9
+ target_branch=${SELECTIVE_TARGET_BRANCH:-$GITHUB_BASE_REF}
10
10
  actor=$GITHUB_ACTOR
11
- sha=$GITHUB_SHA
11
+ sha=${SELECTIVE_SHA:-$GITHUB_SHA}
12
+ run_id=${SELECTIVE_RUN_ID:-$GITHUB_RUN_ID}
13
+ run_attempt=${SELECTIVE_RUN_ATTEMPT:-$GITHUB_RUN_ATTEMPT}
12
14
  commit_message=$(git log --format=%s -n 1 $sha)
13
15
  else
14
16
  platform=$SELECTIVE_PLATFORM
@@ -17,6 +19,8 @@ else
17
19
  target_branch=$SELECTIVE_TARGET_BRANCH
18
20
  actor=$SELECTIVE_ACTOR
19
21
  sha=$SELECTIVE_SHA
22
+ run_id=$SELECTIVE_RUN_ID
23
+ run_attempt=$SELECTIVE_RUN_ATTEMPT
20
24
  commit_message=$(git log --format=%s -n 1 $sha)
21
25
  fi
22
26
 
@@ -29,6 +33,8 @@ cat <<EOF
29
33
  "target_branch": "$target_branch",
30
34
  "actor": "$actor",
31
35
  "sha": "$sha",
36
+ "run_id": "$run_id",
37
+ "run_attempt": "$run_attempt",
32
38
  "commit_message": "$commit_message"
33
39
  }
34
40
  EOF
data/lib/bin/transport CHANGED
Binary file
@@ -14,7 +14,7 @@ module Selective
14
14
  @debug = debug
15
15
  @runner = runner
16
16
  @retries = 0
17
- @runner_id = ENV.fetch("SELECTIVE_RUNNER_ID", generate_runner_id)
17
+ @runner_id = safe_filename(ENV.fetch("SELECTIVE_RUNNER_ID", generate_runner_id))
18
18
  @logger = init_logger(log)
19
19
  end
20
20
 
@@ -23,6 +23,7 @@ module Selective
23
23
  @transport_pid = spawn_transport_process(reconnect ? transport_url + "&reconnect=true" : transport_url)
24
24
 
25
25
  handle_termination_signals(transport_pid)
26
+ wait_for_connectivity
26
27
  run_main_loop
27
28
  rescue NamedPipe::PipeClosedError
28
29
  retry!
@@ -66,8 +67,6 @@ module Selective
66
67
  def run_main_loop
67
68
  loop do
68
69
  message = pipe.read
69
- next sleep(0.1) if message.nil? || message.empty?
70
-
71
70
  response = JSON.parse(message, symbolize_names: true)
72
71
 
73
72
  @logger.info("Received Command: #{response}")
@@ -101,13 +100,15 @@ module Selective
101
100
  def transport_url
102
101
  @transport_url ||= begin
103
102
  api_key = ENV.fetch("SELECTIVE_API_KEY")
104
- run_id = ENV.fetch("SELECTIVE_RUN_ID")
105
- run_attempt = ENV.fetch("SELECTIVE_RUN_ATTEMPT", SecureRandom.uuid)
106
103
  host = ENV.fetch("SELECTIVE_HOST", "wss://app.selective.ci")
107
104
 
108
105
  # Validate that host is a valid websocket url(starts with ws:// or wss://)
109
106
  raise "Invalid host: #{host}" unless host.match?(/^wss?:\/\//)
110
107
 
108
+ run_id = build_env.delete("run_id")
109
+ run_attempt = build_env.delete("run_attempt")
110
+ run_attempt = SecureRandom.uuid if run_attempt.nil? || run_attempt.empty?
111
+
111
112
  params = {
112
113
  "run_id" => run_id,
113
114
  "run_attempt" => run_attempt,
@@ -151,6 +152,31 @@ module Selective
151
152
  end
152
153
  end
153
154
 
155
+ def wait_for_connectivity
156
+ @connectivity = false
157
+
158
+ Thread.new do
159
+ sleep(5)
160
+ unless @connectivity
161
+ puts "Transport process failed to start. Exiting..."
162
+ kill_transport
163
+ exit(1)
164
+ end
165
+ end
166
+
167
+ loop do
168
+ message = pipe.read
169
+
170
+ # The message is nil until the transport opens the pipe
171
+ # for writing. So, we must handle that here.
172
+ next sleep(0.1) if message.nil?
173
+
174
+ response = JSON.parse(message, symbolize_names: true)
175
+ @connectivity = true if response[:command] == "connected"
176
+ break
177
+ end
178
+ end
179
+
154
180
  def handle_termination_signals(pid)
155
181
  ["INT", "TERM"].each do |signal|
156
182
  Signal.trap(signal) do
@@ -173,7 +199,7 @@ module Selective
173
199
 
174
200
  sleep(1)
175
201
  end
176
- rescue NamedPipe::PipeClosedError
202
+ rescue NamedPipe::PipeClosedError, IOError
177
203
  # If the pipe is close, move straight to killing
178
204
  # it forcefully.
179
205
  end
@@ -270,6 +296,13 @@ module Selective
270
296
  @debug
271
297
  end
272
298
 
299
+ def safe_filename(filename)
300
+ filename
301
+ .gsub(/[\/\\:*?"<>|\n\r]+/, '_')
302
+ .gsub(/^\.+|\.+$/, '')
303
+ .strip[0, 255]
304
+ end
305
+
273
306
  def with_error_handling(include_header: true)
274
307
  yield
275
308
  rescue => e
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.4"
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.2
4
+ version: 0.1.4
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: 2023-11-14 00:00:00.000000000 Z
12
+ date: 2023-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk