ruby_ci 0.1.7 → 0.2.0

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: 5f3dc7f160430dc31d9e71e91fa440390233ed36d0101ca70b49d5745257d93a
4
- data.tar.gz: 00eca946cfc469f4999a77eb8ba39be8c0354cb91dbad727a1df1e7333dc54b0
3
+ metadata.gz: d34d2bb75becc90c41cf2366ef0c7d6bb6ccbcc5b33e6c6e460d7a3a5fd6976f
4
+ data.tar.gz: c0846f4d4ed597b738d09687d8a14697e1dff4403fbbf852ab483f70df172b5a
5
5
  SHA512:
6
- metadata.gz: 98bb7204929e650fe2b6866e4475a592f611380752472503bfae719b18de1757d9693ce4c2805a720a3084115ba7ad4fa354354630346fca5725b7c3ebcd1e4c
7
- data.tar.gz: 03dd498f0362f994ce65c077a4341c5892fe57ab9f0992a08377761504c772a8d3ac9cf5ae17c84ac3cf9cd11b8ae7ca9b4d968e59e2884de6182031f438ae88
6
+ metadata.gz: ee9dcf45a74418a994a369c2de76b213c0181462a7ad14ef88782cd0e9cab2f18fb4eb011920a26650f0ac68f6bad32203828a8a617d3675297e66a6656f84ef
7
+ data.tar.gz: f4135d4de92276f7572ef08810fb0873375a28354fd4f7841305ebd6930d26a1d8f9aceb9d25b00dc5a74c28b90365c0b4a3d0554a5b35a2759423e76ab9be8f
@@ -0,0 +1,95 @@
1
+ module Minitest
2
+ module Reporters
3
+ class RubyciReporter
4
+ attr_accessor :tests, :test_results, :ids
5
+
6
+ def initialize
7
+ @tests = {}
8
+ @test_results = {}
9
+ @ids = {}
10
+
11
+ RubyCI.minitest_ws.on(:enq_request) do
12
+ tests
13
+ end
14
+
15
+ RubyCI.minitest_ws.on(:deq) do |api_tests|
16
+ test_results
17
+ end
18
+ end
19
+
20
+ def prerecord(klass, name)
21
+ description = test_description(name)
22
+ path = test_path(klass.name)
23
+
24
+ test_results[path] ||= { run_time: 0.0, file_status: 'pending', test_count: 0, test_counters: { failed: 0, passed: 0, pending: 0 }, '1' => { description: klass.name } }
25
+ test_results[path][:test_count] += 1
26
+
27
+ id = (test_results[path]['1'].keys.size + 1).to_s
28
+ ids[description] = id
29
+
30
+ test_results[path]['1'][id] ||= { status: 'pending', description: description }
31
+ test_results[path]['1'][id][:start] = Minitest.clock_time
32
+
33
+ tests[path] ||= { run_time: 0.0, file_status: 'pending', test_count: 0, test_counters: { failed: 0, passed: 0, pending: 0 }, '1' => {} }
34
+ tests[path][:test_count] += 1
35
+ tests[path]['1'][id] ||= { status: 'pending' }
36
+ end
37
+
38
+ def record(result)
39
+ description = test_description(result.name)
40
+ id = ids[description]
41
+ path = test_path(result.klass)
42
+
43
+ test_results[path]['1'][id][:end] = Minitest.clock_time
44
+ test_results[path]['1'][id][:run_time] = test_results[path]['1'][id][:end] - test_results[path]['1'][id][:start]
45
+ test_results[path]['1'][id][:status] = result_status(result).to_s
46
+ test_results[path][:test_counters][result_status(result)] += 1
47
+ test_results[path][:run_time] += test_results[path]['1'][id][:run_time]
48
+ end
49
+
50
+ def report
51
+ test_results.each do |path, file_results|
52
+ file_status = 'pending'
53
+ file_results['1'].each do |id, test_result|
54
+ next if id == :description
55
+ if (test_result[:status] == 'passed') && (file_status != 'failed')
56
+ file_status = 'passed'
57
+ elsif file_status == 'failed'
58
+ file_status = 'failed'
59
+ end
60
+ end
61
+ test_results[path][:file_status] = file_status
62
+ end
63
+
64
+ RubyCI.minitest_await
65
+ end
66
+
67
+ def method_missing(method, *args)
68
+ return
69
+ end
70
+
71
+ private
72
+
73
+ def test_description(name)
74
+ test_name = name.split('test_').last
75
+ test_name = test_name[2..-1] if test_name.starts_with?(': ')
76
+
77
+ return test_name.strip
78
+ end
79
+
80
+ def test_path(klass)
81
+ return "./#{Object.const_source_location(klass)[0].gsub(Regexp.new("^#{::Rails.root}/"), '')}"
82
+ end
83
+
84
+ def result_status(result)
85
+ if result.passed?
86
+ :passed
87
+ elsif result.skipped?
88
+ :skipped
89
+ else
90
+ :failed
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "reporters/rubyci_reporter"
2
+
3
+ module Minitest
4
+ def self.plugin_rubyci_init(options)
5
+ if ENV['RUBY_CI_SECRET_KEY'].present?
6
+ Minitest.reporter << Minitest::Reporters::RubyciReporter.new
7
+ end
8
+ end
9
+ end
@@ -18,7 +18,7 @@ module RubyCI
18
18
 
19
19
  RubyCI.configure { |c| c.run_key = "rspec" }
20
20
 
21
- RubyCI.ws.on(:enq_request) do
21
+ RubyCI.rspec_ws.on(:enq_request) do
22
22
  example_groups.reduce({}) do |example_group_descriptions, (file, example_groups)|
23
23
  example_groups.each do |example_group|
24
24
  data = RubyCI::ExtractDescriptions.new.call(example_group, count: true)
@@ -47,7 +47,7 @@ module RubyCI
47
47
 
48
48
  reporter.register_listener(formatter, :example_finished)
49
49
 
50
- RubyCI.ws.on(:deq) do |tests|
50
+ RubyCI.rspec_ws.on(:deq) do |tests|
51
51
  tests.each do |test|
52
52
  file, scoped_id = test.split(":", 2)
53
53
  Thread.current[:rubyci_scoped_ids] = scoped_id
@@ -61,7 +61,7 @@ module RubyCI
61
61
  formatter.dump_and_reset
62
62
  end
63
63
 
64
- RubyCI.await
64
+ RubyCI.rspec_await
65
65
 
66
66
  formatter.passed?
67
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCI
4
- VERSION = "0.1.7"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ruby_ci.rb CHANGED
@@ -20,12 +20,20 @@ module RubyCI
20
20
  yield(configuration)
21
21
  end
22
22
 
23
- def ws
24
- @ws ||= WebSocket.new
23
+ def rspec_ws
24
+ @rspec_ws ||= WebSocket.new('rspec')
25
25
  end
26
26
 
27
- def await
28
- ws.await
27
+ def minitest_ws
28
+ @minitest_ws ||= WebSocket.new('minitest')
29
+ end
30
+
31
+ def rspec_await
32
+ rspec_ws.await
33
+ end
34
+
35
+ def minitest_await
36
+ minitest_ws.await
29
37
  end
30
38
 
31
39
  def debug(msg)
@@ -35,13 +43,14 @@ module RubyCI
35
43
 
36
44
  class WebSocket
37
45
  attr_reader :node_index
38
- attr_accessor :connection, :task
46
+ attr_accessor :connection, :task, :run_key
39
47
 
40
48
  SUPPORTED_EVENTS = %i[enq_request deq].freeze
41
49
 
42
- def initialize
50
+ def initialize(run_key)
43
51
  @on = {}
44
52
  @ref = 0
53
+ @run_key = run_key
45
54
  end
46
55
 
47
56
  def on(event, &block)
@@ -148,13 +157,13 @@ module RubyCI
148
157
  end
149
158
 
150
159
  def topic
151
- "test_orchestrator:#{RubyCI.configuration.run_key}-#{RubyCI.configuration.build_id}"
160
+ "test_orchestrator:#{run_key}-#{RubyCI.configuration.build_id}"
152
161
  end
153
162
 
154
163
  def endpoint
155
164
  params = URI.encode_www_form({
156
165
  build_id: RubyCI.configuration.build_id,
157
- run_key: RubyCI.configuration.run_key,
166
+ run_key: run_key,
158
167
  secret_key: RubyCI.configuration.secret_key,
159
168
  branch: RubyCI.configuration.branch,
160
169
  commit: RubyCI.configuration.commit,
@@ -164,7 +173,7 @@ module RubyCI
164
173
 
165
174
  url = "wss://#{RubyCI.configuration.api_url}/test_orchestrators/socket/websocket?#{params}"
166
175
 
167
- Async::HTTP::Endpoint.parse(url)
176
+ Async::HTTP::Endpoint.parse(url, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
168
177
  end
169
178
  end
170
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ale ∴
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2024-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -71,6 +71,8 @@ files:
71
71
  - Rakefile
72
72
  - bin/console
73
73
  - bin/setup
74
+ - lib/minitest/reporters/rubyci_reporter.rb
75
+ - lib/minitest/rubyci_plugin.rb
74
76
  - lib/ruby_ci.rb
75
77
  - lib/ruby_ci/configuration.rb
76
78
  - lib/ruby_ci/exceptions.rb