ruby_ci 0.1.7 → 0.2.1

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: 5f3dc7f160430dc31d9e71e91fa440390233ed36d0101ca70b49d5745257d93a
4
- data.tar.gz: 00eca946cfc469f4999a77eb8ba39be8c0354cb91dbad727a1df1e7333dc54b0
3
+ metadata.gz: e283124f28472dd77c422d918d1add1900eb6b6f220975feca638fd30ec9d17e
4
+ data.tar.gz: 44b1948327549780caf7dfac69d65cc4838acca1e7f84890ff410b420d85ebe9
5
5
  SHA512:
6
- metadata.gz: 98bb7204929e650fe2b6866e4475a592f611380752472503bfae719b18de1757d9693ce4c2805a720a3084115ba7ad4fa354354630346fca5725b7c3ebcd1e4c
7
- data.tar.gz: 03dd498f0362f994ce65c077a4341c5892fe57ab9f0992a08377761504c772a8d3ac9cf5ae17c84ac3cf9cd11b8ae7ca9b4d968e59e2884de6182031f438ae88
6
+ metadata.gz: 81016f3033727cbb53fdb989924e62d4f5f8a8f9963cff8f935b656a08b9582b53329f798324d8427e4522540982947c3dc76d58fbdfae40492b60297c08141f
7
+ data.tar.gz: c499ce521bdc3e5c7a401fb7aa2494df109c0dc9a4796776330c68ad6ffc3bfc5f22d0dc1ecd371c8c2a693116a36f42a5f11e18ec005a42a9e600be62fe7179
@@ -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
@@ -0,0 +1,39 @@
1
+ module RubyCI
2
+ module SimpleCov
3
+ module Reporting
4
+ def self.included base
5
+ base.instance_eval do
6
+ if ENV['RUBY_CI_SECRET_KEY'].present?
7
+ def write_last_run(result)
8
+ ::SimpleCov::LastRun.write(result:
9
+ result.coverage_statistics.transform_values do |stats|
10
+ round_coverage(stats.percent)
11
+ end)
12
+
13
+ source = {}
14
+
15
+ result.source_files.each do |source_file|
16
+ source[source_file.filename.gsub(root, '')] = source_file.src
17
+ end
18
+
19
+ result_json = {}
20
+
21
+ result.as_json.each do |command, data|
22
+ result_json[command] = data
23
+ data['coverage'].clone.each do |src, file_data|
24
+ result_json[command]['coverage'].delete(src)
25
+
26
+ file_data['src'] = source[src.gsub(root, '')]
27
+
28
+ result_json[command]['coverage'][src.gsub(root, '')] = file_data
29
+ end
30
+ end
31
+
32
+ RubyCI.report_simplecov(result_json.to_json)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "simple_cov/reporting"
2
+
3
+ module RubyCI
4
+ module SimpleCov
5
+ ::SimpleCov.send(:include, RubyCI::SimpleCov::Reporting)
6
+ end
7
+ 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.1"
5
5
  end
data/lib/ruby_ci.rb CHANGED
@@ -20,12 +20,36 @@ 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 report_simplecov(results)
32
+ data = {
33
+ build_id: RubyCI.configuration.build_id,
34
+ run_key: 'simplecov',
35
+ secret_key: RubyCI.configuration.secret_key,
36
+ branch: RubyCI.configuration.branch,
37
+ commit: RubyCI.configuration.commit,
38
+ commit_msg: RubyCI.configuration.commit_msg,
39
+ author: RubyCI.configuration.author.to_json,
40
+ content: results
41
+ }
42
+
43
+ uri = URI('https://fast.ruby.ci/api/runs')
44
+ res = Net::HTTP.post_form(uri, data)
45
+ end
46
+
47
+ def rspec_await
48
+ rspec_ws.await
49
+ end
50
+
51
+ def minitest_await
52
+ minitest_ws.await
29
53
  end
30
54
 
31
55
  def debug(msg)
@@ -35,13 +59,14 @@ module RubyCI
35
59
 
36
60
  class WebSocket
37
61
  attr_reader :node_index
38
- attr_accessor :connection, :task
62
+ attr_accessor :connection, :task, :run_key
39
63
 
40
64
  SUPPORTED_EVENTS = %i[enq_request deq].freeze
41
65
 
42
- def initialize
66
+ def initialize(run_key)
43
67
  @on = {}
44
68
  @ref = 0
69
+ @run_key = run_key
45
70
  end
46
71
 
47
72
  def on(event, &block)
@@ -148,13 +173,13 @@ module RubyCI
148
173
  end
149
174
 
150
175
  def topic
151
- "test_orchestrator:#{RubyCI.configuration.run_key}-#{RubyCI.configuration.build_id}"
176
+ "test_orchestrator:#{run_key}-#{RubyCI.configuration.build_id}"
152
177
  end
153
178
 
154
179
  def endpoint
155
180
  params = URI.encode_www_form({
156
181
  build_id: RubyCI.configuration.build_id,
157
- run_key: RubyCI.configuration.run_key,
182
+ run_key: run_key,
158
183
  secret_key: RubyCI.configuration.secret_key,
159
184
  branch: RubyCI.configuration.branch,
160
185
  commit: RubyCI.configuration.commit,
@@ -164,7 +189,7 @@ module RubyCI
164
189
 
165
190
  url = "wss://#{RubyCI.configuration.api_url}/test_orchestrators/socket/websocket?#{params}"
166
191
 
167
- Async::HTTP::Endpoint.parse(url)
192
+ Async::HTTP::Endpoint.parse(url, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
168
193
  end
169
194
  end
170
195
  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.1
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-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -71,12 +71,16 @@ 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
77
79
  - lib/ruby_ci/extract_definitions.rb
78
80
  - lib/ruby_ci/rspec_formatter.rb
79
81
  - lib/ruby_ci/runner_prepend.rb
82
+ - lib/ruby_ci/simple_cov.rb
83
+ - lib/ruby_ci/simple_cov/reporting.rb
80
84
  - lib/ruby_ci/version.rb
81
85
  - ruby_ci.gemspec
82
86
  homepage: https://github.com/RubyCI/ruby_ci_gem