selective-ruby-core 0.1.0-x86_64-darwin → 0.1.2-x86_64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d4b5cf15777008289547b5727ecea62ccabcf1fab4f6d4ee28a2777f6e0edee
4
- data.tar.gz: 2fcf66163491822036c25a0a25c95253750bd41a7e858efe3b5cee1caaf200ab
3
+ metadata.gz: de5a1cbd67c1d87b590371321c194cd39ebb4c48262b2cebcbf9af3a167d4d37
4
+ data.tar.gz: 1b9841d87eae5f184b4a2048262a7871b48339d0b31f22f8b0f1311d2c79932c
5
5
  SHA512:
6
- metadata.gz: f61735f940a787998f234c517fff8a152be58af9f4fa92ba2e218020325923110af45f3de90ee09197b2372e3bab5cd229086cf763465585053c0adc3d206176
7
- data.tar.gz: '097effb81222320ac79d2775d91b4d9efd297bcff8fc96f520112032552ab0847ec755266b39cb31a5c29388111dd9c6eb92ad3c4c88a13401275cd7d4ef4452'
6
+ metadata.gz: 32ba16bd2e9818f3bbdd0687715c4804688f12fbf16981688f879615318a6dd17d1f5b7ac7e76e10fa6c159ded6b54bf2e77b2e98affc2e4580935db90fbf345
7
+ data.tar.gz: 5036c3e0f58bd830f5c7362f051baf5654c85020bd473aa2f9de32b16c3517714b37ac004ec770e3b63d0f8e659593257084b005b1467f5143fbfdbce54830cb
data/Rakefile CHANGED
@@ -1,14 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
-
5
- # Override the guard_clean task to be a no-op
6
- Rake::Task["release:guard_clean"].clear
7
-
8
- task "release:guard_clean" do
9
- # Intentionally blank to skip the check
10
- end
11
-
12
4
  require "rspec/core/rake_task"
13
5
 
14
6
  RSpec::Core::RakeTask.new(:spec)
data/lib/bin/build_env.sh CHANGED
@@ -3,20 +3,20 @@
3
3
  # Detect the platform (only GitHub Actions in this case)
4
4
  if [ -n "$GITHUB_ACTIONS" ]; then
5
5
  # Get environment variables
6
- platform="github_actions"
7
- branch="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
8
- pr_title="$PR_TITLE"
9
- target_branch="${GITHUB_BASE_REF}"
10
- actor="$GITHUB_ACTOR"
11
- sha="$GITHUB_SHA"
6
+ platform=github_actions
7
+ branch=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}
8
+ pr_title=$SELECTIVE_PR_TITLE
9
+ target_branch=${GITHUB_BASE_REF}
10
+ actor=$GITHUB_ACTOR
11
+ sha=$GITHUB_SHA
12
12
  commit_message=$(git log --format=%s -n 1 $sha)
13
13
  else
14
- platform="$SELECTIVE_PLATFORM"
15
- branch="$SELECTIVE_BRANCH"
16
- pr_title="$SELECTIVE_PR_TITLE"
17
- target_branch="$SELECTIVE_TARGET_BRANCH"
18
- actor="$SELECTIVE_ACTOR"
19
- sha="$SELECTIVE_SHA"
14
+ platform=$SELECTIVE_PLATFORM
15
+ branch=$SELECTIVE_BRANCH
16
+ pr_title=$SELECTIVE_PR_TITLE
17
+ target_branch=$SELECTIVE_TARGET_BRANCH
18
+ actor=$SELECTIVE_ACTOR
19
+ sha=$SELECTIVE_SHA
20
20
  commit_message=$(git log --format=%s -n 1 $sha)
21
21
  fi
22
22
 
@@ -1,6 +1,8 @@
1
1
  require "logger"
2
2
  require "uri"
3
3
  require "json"
4
+ require "fileutils"
5
+ require "open3"
4
6
 
5
7
  module Selective
6
8
  module Ruby
@@ -8,12 +10,12 @@ module Selective
8
10
  class Controller
9
11
  @@selective_suppress_reporting = false
10
12
 
11
- def initialize(runner, debug = false)
13
+ def initialize(runner, debug: false, log: false)
12
14
  @debug = debug
13
15
  @runner = runner
14
16
  @retries = 0
15
17
  @runner_id = ENV.fetch("SELECTIVE_RUNNER_ID", generate_runner_id)
16
- @logger = Logger.new("log/#{runner_id}.log")
18
+ @logger = init_logger(log)
17
19
  end
18
20
 
19
21
  def start(reconnect: false)
@@ -52,6 +54,15 @@ module Selective
52
54
 
53
55
  BUILD_ENV_SCRIPT_PATH = "../../../bin/build_env.sh".freeze
54
56
 
57
+ def init_logger(enabled)
58
+ if enabled
59
+ FileUtils.mkdir_p("log")
60
+ Logger.new("log/#{runner_id}.log")
61
+ else
62
+ Logger.new("/dev/null")
63
+ end
64
+ end
65
+
55
66
  def run_main_loop
56
67
  loop do
57
68
  message = pipe.read
@@ -111,8 +122,10 @@ module Selective
111
122
  end
112
123
 
113
124
  def build_env
114
- result = `#{Pathname.new(__dir__) + BUILD_ENV_SCRIPT_PATH}`
115
- JSON.parse(result)
125
+ @build_env ||= begin
126
+ result = `#{Pathname.new(__dir__) + BUILD_ENV_SCRIPT_PATH}`
127
+ JSON.parse(result)
128
+ end
116
129
  end
117
130
 
118
131
  def spawn_transport_process(url)
@@ -123,7 +136,6 @@ module Selective
123
136
  # The get_transport script is not released with the gem, so this
124
137
  # code is intended for development/CI purposes.
125
138
  if !File.exist?(transport_path) && File.exist?(get_transport_path)
126
- require "open3"
127
139
  output, status = Open3.capture2e(get_transport_path)
128
140
  if !status.success?
129
141
  puts <<~TEXT
@@ -175,8 +187,8 @@ module Selective
175
187
 
176
188
  def handle_command(response)
177
189
  case response[:command]
178
- when "init"
179
- print_init(response[:runner_id])
190
+ when "print_notice"
191
+ print_notice(response[:message])
180
192
  when "test_manifest"
181
193
  handle_test_manifest
182
194
  when "run_test_cases"
@@ -189,10 +201,11 @@ module Selective
189
201
  handle_print_message(response[:message])
190
202
  when "close"
191
203
  handle_close(response[:exit_status])
192
-
193
- # This is here for the sake of test where we
194
- # cannot exit but we need to break the loop
204
+ # This return is here for the sake of test where
205
+ # we cannot exit but we need to break the loop
195
206
  return false
207
+ else
208
+ raise "Unknown command received: #{response[:command]}" if debug?
196
209
  end
197
210
 
198
211
  true
@@ -207,10 +220,9 @@ module Selective
207
220
  def handle_test_manifest
208
221
  self.class.restore_reporting!
209
222
  @logger.info("Sending Response: test_manifest")
210
- write({type: "test_manifest", data: {
211
- test_cases: runner.manifest["examples"],
212
- modified_test_files: modified_test_files
213
- }})
223
+ data = {test_cases: runner.manifest["examples"]}
224
+ data[:modified_test_files] = modified_test_files unless modified_test_files.nil?
225
+ write({type: "test_manifest", data: data})
214
226
  end
215
227
 
216
228
  def handle_run_test_cases(test_cases)
@@ -227,9 +239,17 @@ module Selective
227
239
  end
228
240
 
229
241
  def modified_test_files
230
- # Todo: This should find files changed in the current branch
231
- `git diff --name-only`.split("\n").filter do |f|
232
- f.match?(/^#{runner.base_test_path}/)
242
+ @modified_test_files ||= begin
243
+ target_branch = build_env["target_branch"]
244
+ return [] if target_branch.nil? || target_branch.empty?
245
+
246
+ output, status = Open3.capture2e("git diff #{target_branch} --name-only")
247
+
248
+ if status.success?
249
+ output.split("\n").filter do |f|
250
+ f.match?(/^#{runner.base_test_path}/)
251
+ end
252
+ end
233
253
  end
234
254
  end
235
255
 
@@ -285,10 +305,10 @@ module Selective
285
305
  TEXT
286
306
  end
287
307
 
288
- def print_init(runner_id)
308
+ def print_notice(message)
289
309
  puts_indented <<~TEXT
290
310
  #{banner}
291
- Runner ID: #{runner_id.gsub("selgen-", "")}
311
+ #{message}
292
312
  TEXT
293
313
  end
294
314
 
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.1.0"
6
+ VERSION = "0.1.2"
7
7
  end
8
8
  end
9
9
  end
@@ -24,6 +24,7 @@ module Selective
24
24
  class Init
25
25
  def initialize(args)
26
26
  @debug = !args.delete("--debug").nil?
27
+ @log = !args.delete("--log").nil?
27
28
  @runner_name, @args, @command = parse_args(args)
28
29
  require_runner
29
30
  end
@@ -34,10 +35,10 @@ module Selective
34
35
 
35
36
  private
36
37
 
37
- attr_reader :debug, :runner_name, :args, :command
38
+ attr_reader :debug, :log, :runner_name, :args, :command
38
39
 
39
40
  def run
40
- Selective::Ruby::Core::Controller.new(runner, debug).send(command)
41
+ Selective::Ruby::Core::Controller.new(runner, debug: debug, log: log).send(command)
41
42
  end
42
43
 
43
44
  def parse_args(args)
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.0
4
+ version: 0.1.2
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: 2023-11-03 00:00:00.000000000 Z
12
+ date: 2023-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zeitwerk