rspec-buildkite-analytics 0.6.1 → 0.8.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: 541f8d1bf4465e411f3fa17757b1c13bc073ea361db1e66973060cb673779d39
4
- data.tar.gz: 87bb5b43638e2db1951ab0fc0a60a67f5edc7f41c0b4d4735bf75d4202745d21
3
+ metadata.gz: a29588419eb727d74849c54b0d38f5b90974c3f58f083e48958a17288a1dc1fe
4
+ data.tar.gz: 1fd5fd323f7737c247b61bcd87ea9778e3f020601514eb52777c0ba5871c24aa
5
5
  SHA512:
6
- metadata.gz: e98d13112dddf07fbad1cef13042de7fadd856b3c92202859ebf7e9c935b72eb8d960525181c726fd2ac1d15f72e9252273c9c1e8553f466a0aa415e0307b7df
7
- data.tar.gz: 9380dce5392e09ef0758780e8a58586f11aabc57ca11ea345d2ae3d7a0f9fa2bac1c982e514b0b556faddf10b0b5ba02f9495320a628bf7add4700898fb29d0e
6
+ metadata.gz: 45624d6a321c8ff16008e259b4a3eb3f118449d36947f1cb0efb86c7e988ee3e904a2665be517b4be2cd8075d4c1352d8356df88ac43c615664ec28383ced50f
7
+ data.tar.gz: fdb57102cd80974a01e939e8ab8bc8ae3ce22f39ff5a6862cc7cdc9d5250672a93ff966dfa391e47e80cdfaf70354082f0afd9ca1f6d4e1104edb53dbc11d977
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.8.0
4
+
5
+ - Support multiple CI platforms and generic env #80 — @blaknite
6
+ - Replace invalid UTF-8 characters in test names #85 — @mariovisic
7
+ - Relax Active Support constraint #87 — @ags
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-buildkite-analytics (0.6.1)
5
- activesupport (>= 5.2, <= 7.0)
4
+ rspec-buildkite-analytics (0.8.0)
5
+ activesupport (>= 5.2, < 8)
6
6
  rspec-core (~> 3.10)
7
7
  rspec-expectations (~> 3.10)
8
8
  websocket (~> 1.2)
@@ -10,17 +10,16 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.1.4.1)
13
+ activesupport (7.0.2.3)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
17
17
  tzinfo (~> 2.0)
18
- zeitwerk (~> 2.3)
19
- concurrent-ruby (1.1.9)
18
+ concurrent-ruby (1.1.10)
20
19
  diff-lcs (1.4.4)
21
- i18n (1.8.11)
20
+ i18n (1.10.0)
22
21
  concurrent-ruby (~> 1.0)
23
- minitest (5.14.4)
22
+ minitest (5.15.0)
24
23
  rake (13.0.6)
25
24
  rspec (3.10.0)
26
25
  rspec-core (~> 3.10.0)
@@ -38,7 +37,6 @@ GEM
38
37
  tzinfo (2.0.4)
39
38
  concurrent-ruby (~> 1.0)
40
39
  websocket (1.2.9)
41
- zeitwerk (2.5.1)
42
40
 
43
41
  PLATFORMS
44
42
  ruby
@@ -2,26 +2,85 @@
2
2
 
3
3
  require "securerandom"
4
4
 
5
- module RSpec::Buildkite::Analytics::CI
5
+ class RSpec::Buildkite::Analytics::CI
6
6
  def self.env
7
- if ENV["BUILDKITE_BUILD_ID"]
8
- {
9
- "CI" => "buildkite",
10
- "key" => ENV["BUILDKITE_BUILD_ID"],
11
- "url" => ENV["BUILDKITE_BUILD_URL"],
12
- "branch" => ENV["BUILDKITE_BRANCH"],
13
- "commit_sha" => ENV["BUILDKITE_COMMIT"],
14
- "number" => ENV["BUILDKITE_BUILD_NUMBER"],
15
- "job_id" => ENV["BUILDKITE_JOB_ID"],
16
- "message" => ENV["BUILDKITE_MESSAGE"],
17
- "debug" => ENV["BUILDKITE_ANALYTICS_DEBUG_ENABLED"]
18
- }
19
- else
20
- {
21
- "CI" => nil,
22
- "key" => SecureRandom.uuid,
23
- "debug" => ENV["BUILDKITE_ANALYTICS_DEBUG_ENABLED"]
24
- }
25
- end
7
+ new.env
8
+ end
9
+
10
+ # The analytics env are more specific than the automatic ci platform env.
11
+ # If they've been specified we'll assume the user wants to use that value instead.
12
+ def env
13
+ ci_env.merge(analytics_env)
14
+ end
15
+
16
+ private
17
+
18
+ def ci_env
19
+ return buildkite if ENV["BUILDKITE_BUILD_ID"]
20
+ return github_actions if ENV["GITHUB_RUN_NUMBER"]
21
+ return circleci if ENV["CIRCLE_BUILD_NUM"]
22
+ return generic if ENV["CI"]
23
+
24
+ {
25
+ "CI" => nil,
26
+ "key" => SecureRandom.uuid,
27
+ }
28
+ end
29
+
30
+ def analytics_env
31
+ {
32
+ "key" => ENV["BUILDKITE_ANALYTICS_KEY"],
33
+ "url" => ENV["BUILDKITE_ANALYTICS_URL"],
34
+ "branch" => ENV["BUILDKITE_ANALYTICS_BRANCH"],
35
+ "commit_sha" => ENV["BUILDKITE_ANALYTICS_SHA"],
36
+ "number" => ENV["BUILDKITE_ANALYTICS_NUMBER"],
37
+ "job_id" => ENV["BUILDKITE_ANALYTICS_JOB_ID"],
38
+ "message" => ENV["BUILDKITE_ANANLYTICS_MESSAGE"],
39
+ "debug" => ENV["BUILDKITE_ANALYTICS_DEBUG_ENABLED"],
40
+ "version" => RSpec::Buildkite::Analytics::VERSION,
41
+ "collector" => RSpec::Buildkite::Analytics::NAME,
42
+ }.compact
43
+ end
44
+
45
+ def generic
46
+ {
47
+ "CI" => "generic",
48
+ "key" => SecureRandom.uuid,
49
+ }
50
+ end
51
+
52
+ def buildkite
53
+ {
54
+ "CI" => "buildkite",
55
+ "key" => ENV["BUILDKITE_BUILD_ID"],
56
+ "url" => ENV["BUILDKITE_BUILD_URL"],
57
+ "branch" => ENV["BUILDKITE_BRANCH"],
58
+ "commit_sha" => ENV["BUILDKITE_COMMIT"],
59
+ "number" => ENV["BUILDKITE_BUILD_NUMBER"],
60
+ "job_id" => ENV["BUILDKITE_JOB_ID"],
61
+ "message" => ENV["BUILDKITE_MESSAGE"],
62
+ }
63
+ end
64
+
65
+ def github_actions
66
+ {
67
+ "CI" => "github_actions",
68
+ "key" => "#{ENV["GITHUB_ACTION"]}-#{ENV["GITHUB_RUN_NUMBER"]}-#{ENV["GITHUB_RUN_ATTEMPT"]}",
69
+ "url" => File.join("https://github.com", ENV["GITHUB_REPOSITORY"], "actions/runs", ENV["GITHUB_RUN_ID"]),
70
+ "branch" => ENV["GITHUB_REF"],
71
+ "commit_sha" => ENV["GITHUB_SHA"],
72
+ "number" => ENV["GITHUB_RUN_NUMBER"],
73
+ }
74
+ end
75
+
76
+ def circleci
77
+ {
78
+ "CI" => "circleci",
79
+ "key" => "#{ENV["CIRCLE_WORKFLOW_ID"]}-#{ENV["CIRCLE_BUILD_NUM"]}",
80
+ "url" => ENV["CIRCLE_BUILD_URL"],
81
+ "branch" => ENV["CIRCLE_BRANCH"],
82
+ "commit_sha" => ENV["CIRCLE_SHA1"],
83
+ "number" => ENV["CIRCLE_BUILD_NUM"],
84
+ }
26
85
  end
27
86
  end
@@ -52,9 +52,22 @@ module RSpec::Buildkite::Analytics
52
52
 
53
53
  @logger = Logger.new
54
54
 
55
- connect
56
- rescue TimeoutError, InitialConnectionFailure => e
57
- $stderr.puts "rspec-buildkite-analytics could not establish an initial connection with Buildkite due to #{e.message}. You may be missing some data for this test suite, please contact support."
55
+ reconnection_count = 0
56
+
57
+ begin
58
+ reconnection_count += 1
59
+ connect
60
+ rescue TimeoutError, InitialConnectionFailure => e
61
+ @logger.write("rspec-buildkite-analytics could not establish an initial connection with Buildkite due to #{e}. Attempting retry #{reconnection_count} of #{MAX_RECONNECTION_ATTEMPTS}...")
62
+ if reconnection_count > MAX_RECONNECTION_ATTEMPTS
63
+ $stderr.puts "rspec-buildkite-analytics could not establish an initial connection with Buildkite due to #{e.message} after #{MAX_RECONNECTION_ATTEMPTS} attempts. You may be missing some data for this test suite, please contact support if this issue persists."
64
+ else
65
+ sleep(WAIT_BETWEEN_RECONNECTIONS)
66
+ @logger.write("retrying reconnection")
67
+ retry
68
+ end
69
+ end
70
+ init_write_thread
58
71
  end
59
72
 
60
73
  def disconnected(connection)
@@ -76,7 +89,8 @@ module RSpec::Buildkite::Analytics
76
89
  begin
77
90
  reconnection_count += 1
78
91
  connect
79
- rescue SocketConnection::HandshakeError, RejectedSubscription, TimeoutError, SocketConnection::SocketError => e
92
+ init_write_thread
93
+ rescue SocketConnection::HandshakeError, RejectedSubscription, TimeoutError, InitialConnectionFailure, SocketConnection::SocketError => e
80
94
  @logger.write("failed reconnection attempt #{reconnection_count} due to #{e}")
81
95
  if reconnection_count > MAX_RECONNECTION_ATTEMPTS
82
96
  $stderr.puts "rspec-buildkite-analytics experienced a disconnection and could not reconnect to Buildkite due to #{e.message}. Please contact support."
@@ -170,8 +184,10 @@ module RSpec::Buildkite::Analytics
170
184
  wait_for_confirm
171
185
 
172
186
  @logger.write("connected")
187
+ end
173
188
 
174
- # As this connect method can be called multiple times in the
189
+ def init_write_thread
190
+ # As this method can be called multiple times in the
175
191
  # reconnection process, kill prev write threads (if any) before
176
192
  # setting up the new one
177
193
  @write_thread&.kill
@@ -42,7 +42,7 @@ module RSpec::Buildkite::Analytics
42
42
  end
43
43
 
44
44
  def as_hash
45
- {
45
+ strip_invalid_utf8_chars(
46
46
  id: @id,
47
47
  scope: example.example_group.metadata[:full_description],
48
48
  name: example.description,
@@ -53,14 +53,14 @@ module RSpec::Buildkite::Analytics
53
53
  failure_reason: failure_reason,
54
54
  failure_expanded: failure_expanded,
55
55
  history: history,
56
- }.with_indifferent_access.compact
56
+ ).with_indifferent_access.compact
57
57
  end
58
58
 
59
59
  private
60
60
 
61
61
  def generate_file_name(example)
62
62
  file_path_regex = /^(.*?\.(rb|feature))/
63
- identifier_file_name = example.id[file_path_regex]
63
+ identifier_file_name = strip_invalid_utf8_chars(example.id)[file_path_regex]
64
64
  location_file_name = example.location[file_path_regex]
65
65
 
66
66
  if identifier_file_name != location_file_name
@@ -78,6 +78,18 @@ module RSpec::Buildkite::Analytics
78
78
  identifier_file_name
79
79
  end
80
80
  end
81
+
82
+ def strip_invalid_utf8_chars(object)
83
+ if object.is_a?(Hash)
84
+ Hash[object.map { |key, value| [key, strip_invalid_utf8_chars(value)] }]
85
+ elsif object.is_a?(Array)
86
+ object.map { |value| strip_invalid_utf8_chars(value) }
87
+ elsif object.is_a?(String)
88
+ object.encode('UTF-8', :invalid => :replace, :undef => :replace)
89
+ else
90
+ object
91
+ end
92
+ end
81
93
  end
82
94
 
83
95
  def self.traces
@@ -125,6 +137,8 @@ module RSpec::Buildkite::Analytics
125
137
  puts "Buildkite Test Analytics: Error communicating with the server: #{e.message}"
126
138
  end
127
139
 
140
+ return unless response
141
+
128
142
  case response.code
129
143
  when "401"
130
144
  puts "Buildkite Test Analytics: Invalid Suite API key. Please double check your Suite API key."
@@ -3,7 +3,8 @@
3
3
  module RSpec
4
4
  module Buildkite
5
5
  module Analytics
6
- VERSION = "0.6.1"
6
+ VERSION = "0.8.0"
7
+ NAME = "rspec-buildkite"
7
8
  end
8
9
  end
9
10
  end
@@ -30,4 +30,10 @@ module RSpec::Buildkite::Analytics
30
30
 
31
31
  self::Uploader.configure
32
32
  end
33
+
34
+ def self.annotate(content)
35
+ tracer = RSpec::Buildkite::Analytics::Uploader.tracer
36
+ tracer&.enter("annotation", **{ content: content })
37
+ tracer&.leave
38
+ end
33
39
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
26
26
 
27
- spec.add_dependency "activesupport", ">= 5.2", "<= 7.0"
27
+ spec.add_dependency "activesupport", ">= 5.2", "< 8"
28
28
  spec.add_dependency "rspec-core", '~> 3.10'
29
29
  spec.add_dependency "rspec-expectations", '~> 3.10'
30
30
  spec.add_dependency "websocket", '~> 1.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-buildkite-analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-09 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,9 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.2'
20
- - - "<="
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.0'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +27,9 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.2'
30
- - - "<="
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '8'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec-core
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,7 @@ extra_rdoc_files: []
81
81
  files:
82
82
  - ".gitignore"
83
83
  - ".rspec"
84
+ - CHANGELOG.md
84
85
  - Gemfile
85
86
  - Gemfile.lock
86
87
  - LICENSE.txt
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubygems_version: 3.1.4
125
+ rubygems_version: 3.3.3
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Track execution of specs and report to Buildkite Analytics