buildkite-test_collector 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e6c042c033ec5dce4350b7bc365b7367d2b02d188b661ceffeab42ac3b44a93
4
+ data.tar.gz: b4a9669cbc466980b6a9f7cf4c971f049c799ea2846013165eb53bf7c153b75b
5
+ SHA512:
6
+ metadata.gz: e81965dc948812b4ea7a9045bba5db5cdc6a3a634e5b92b201eaf3636c09ce473159d4a664d13575730620d1fa4994814b0515e503cb2a4d4f9c4b41a0559428
7
+ data.tar.gz: 4518c2d5dfa75d3e22177341b43a1ff85e15e329257844b9c6866dc787d1226558bedaa675e3659a31f44c7a4cb9213bd9b77ec622a71586b95d07f3052580a9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # CHANGELOG
2
+
3
+ ## v1.0.0
4
+
5
+ - Option to disable detailed tracing #108 - @blanknite
6
+ - minitest support (beta) #103 - @mariovisic, @blaknite
7
+ - Handle re-raised disconnect exceptions #102 - @JuantoFatas
8
+ - Make trace lookup faster using a Hash #98 - @blaknite, @mariovisic
9
+ - Introduce more configurable logging #97 - @JuanitoFatas
10
+
11
+ ## v0.8.1
12
+
13
+ - Improve the EOT confirmation #93 — @blaknite
14
+
15
+ ## v0.8.0
16
+
17
+ - Support multiple CI platforms and generic env #80 — @blaknite
18
+ - Replace invalid UTF-8 characters in test names #85 — @mariovisic
19
+ - Relax Active Support constraint #87 — @ags
@@ -0,0 +1,133 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, caste, color, religion, or sexual
11
+ identity and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the overall
27
+ community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or advances of
32
+ any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email address,
36
+ without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ `support+analytics@buildkite.com`.
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series of
87
+ actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or permanent
94
+ ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within the
114
+ community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127
+ [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rspec-buildkite-analytics.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ buildkite-test_collector (1.0.0)
5
+ activesupport (>= 5.2, < 8)
6
+ websocket (~> 1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ concurrent-ruby (1.1.10)
17
+ diff-lcs (1.4.4)
18
+ i18n (1.10.0)
19
+ concurrent-ruby (~> 1.0)
20
+ minitest (5.15.0)
21
+ rake (13.0.6)
22
+ rspec (3.10.0)
23
+ rspec-core (~> 3.10.0)
24
+ rspec-expectations (~> 3.10.0)
25
+ rspec-mocks (~> 3.10.0)
26
+ rspec-core (3.10.1)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-expectations (3.10.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-mocks (3.10.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-support (3.10.3)
35
+ tzinfo (2.0.4)
36
+ concurrent-ruby (~> 1.0)
37
+ websocket (1.2.9)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ buildkite-test_collector!
44
+ rake (~> 13.0)
45
+ rspec (~> 3.0)
46
+ rspec-core (~> 3.10)
47
+ rspec-expectations (~> 3.10)
48
+
49
+ BUNDLED WITH
50
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Buildkite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Buildkite Collectors for Ruby
2
+
3
+ Official [Buildkite Test Analytics](https://buildkite.com/test-analytics) collectors for Ruby test frameworks ✨
4
+
5
+ ⚒ **Supported test frameworks:** RSpec, Minitest, and [more coming soon](https://github.com/buildkite/test-collector-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22test+frameworks%22).
6
+
7
+ 📦 **Supported CI systems:** Buildkite, GitHub Actions, CircleCI, and others via the `BUILDKITE_ANALYTICS_*` environment variables.
8
+
9
+ ## 👉 Installing
10
+
11
+ ### Step 1
12
+
13
+ [Create a test suite](https://buildkite.com/docs/test-analytics), and copy the API token that it gives you.
14
+
15
+ Add the [`buildkite-test_collector`](https://rubygems.org/gems/buildkite-test_collector) gem:
16
+
17
+ ```shell
18
+ gem install buildkite-test_collector
19
+ ```
20
+
21
+ Or add this to your Gemfile’s test group:
22
+
23
+ ```ruby
24
+ group :test do
25
+ gem "buildkite-test_collector"
26
+ end
27
+ ```
28
+
29
+ ### Step 2
30
+
31
+ #### RSpec
32
+
33
+ Add the following code to your RSpec setup file:
34
+
35
+ ```ruby
36
+ # spec/spec_helper.rb
37
+ require "buildkite/test_collector"
38
+ Buildkite::TestCollector.configure(hook: :rspec)
39
+ ```
40
+
41
+ Run your tests locally:
42
+
43
+ ```shell
44
+ BUILDKITE_ANALYTICS_TOKEN=xyz rspec
45
+ ```
46
+
47
+ #### Minitest
48
+
49
+ Add the following code to your Minitest setup file:
50
+
51
+ ```ruby
52
+ # test/test_helper.rb
53
+ require "buildkite/test_collector"
54
+ Buildkite::TestCollector.configure(hook: :minitest)
55
+ ```
56
+
57
+ Run your tests locally:
58
+
59
+ ```shell
60
+ BUILDKITE_ANALYTICS_TOKEN=xyz rake
61
+ ```
62
+
63
+ ### Step 3
64
+
65
+ Add the `BUILDKITE_ANALYTICS_TOKEN` secret to your CI, push your changes to a branch, and open a pull request 🎉
66
+
67
+ ```bash
68
+ git checkout -b add-buildkite-test-analytics
69
+ git commit -am "Add Buildkite Test Analytics"
70
+ git push origin add-buildkite-test-analytics
71
+ ```
72
+
73
+ ## 🔍 Debugging
74
+
75
+ To enable debugging output, set the `BUILDKITE_ANALYTICS_DEBUG_ENABLED` environment variable to `true`.
76
+
77
+ ## 🔜 Roadmap
78
+
79
+ See the [GitHub 'enhancement' issues](https://github.com/buildkite/test-collector-ruby/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement) for planned features. Pull requests are always welcome, and we’ll give you feedback and guidance if you choose to contribute 💚
80
+
81
+ ## ⚒ Developing
82
+
83
+ After cloning the repository, install the dependencies:
84
+
85
+ ```
86
+ bundle
87
+ ```
88
+
89
+ And run the tests:
90
+
91
+ ```
92
+ bundle exec rspec
93
+ ```
94
+
95
+ Useful resources for developing collectors include the [Buildkite Test Analytics docs](https://buildkite.com/docs/test-analytics).
96
+
97
+ ## 👩‍💻 Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test-collector-ruby
100
+
101
+ ## 📜 MIT License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rspec/buildkite/analytics"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/buildkite/test_collector/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "buildkite-test_collector"
7
+ spec.version = Buildkite::TestCollector::VERSION
8
+ spec.authors = ["Buildkite"]
9
+ spec.email = ["support+analytics@buildkite.com"]
10
+
11
+ spec.summary = "Track test executions and report to Buildkite Test Analytics"
12
+ spec.homepage = "https://github.com/buildkite/test-collector-ruby"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/buildkite/test-collector-ruby"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
+ end
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
26
+
27
+ spec.add_dependency "activesupport", ">= 5.2", "< 8"
28
+ spec.add_dependency "websocket", '~> 1.2'
29
+
30
+ spec.add_development_dependency "rspec-core", '~> 3.10'
31
+ spec.add_development_dependency "rspec-expectations", '~> 3.10'
32
+ end
data/buildkite.yaml ADDED
@@ -0,0 +1,8 @@
1
+ steps:
2
+ - label: ":rspec: Tests"
3
+ command:
4
+ - "bundle"
5
+ - "bundle exec rake"
6
+ plugins:
7
+ - docker#v3.7.0:
8
+ image: ruby:latest
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ class Buildkite::TestCollector::CI
6
+ def self.env
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_ANALYTICS_MESSAGE"],
39
+ "debug" => ENV["BUILDKITE_ANALYTICS_DEBUG_ENABLED"],
40
+ "version" => Buildkite::TestCollector::VERSION,
41
+ "collector" => Buildkite::TestCollector::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
+ }
85
+ end
86
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module Buildkite::TestCollector
6
+ class HTTPClient
7
+ attr :authorization_header
8
+ def initialize(url)
9
+ @url = url
10
+ @authorization_header = "Token token=\"#{Buildkite::TestCollector.api_token}\""
11
+ end
12
+
13
+ def post
14
+ contact_uri = URI.parse(url)
15
+
16
+ http = Net::HTTP.new(contact_uri.host, contact_uri.port)
17
+ http.use_ssl = contact_uri.scheme == "https"
18
+
19
+ contact = Net::HTTP::Post.new(contact_uri.path, {
20
+ "Authorization" => authorization_header,
21
+ "Content-Type" => "application/json",
22
+ })
23
+ contact.body = {
24
+ run_env: Buildkite::TestCollector::CI.env,
25
+ format: "websocket"
26
+ }.to_json
27
+
28
+ http.request(contact)
29
+ end
30
+
31
+ private
32
+
33
+ attr :url
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest"
4
+
5
+ require_relative "../uploader"
6
+ require_relative "../minitest_plugin"
7
+
8
+ Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader
9
+
10
+ class MiniTest::Test
11
+ include Buildkite::TestCollector::MinitestPlugin
12
+ end
13
+
14
+ Buildkite::TestCollector.enable_tracing!
15
+
16
+ Buildkite::TestCollector::Uploader.configure
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core"
4
+ require "rspec/expectations"
5
+
6
+ require_relative "../uploader"
7
+ require_relative "../rspec_plugin/reporter"
8
+ require_relative "../rspec_plugin/trace"
9
+
10
+ Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:suite) do
14
+ config.add_formatter Buildkite::TestCollector::RSpecPlugin::Reporter
15
+
16
+ Buildkite::TestCollector::Uploader.configure
17
+ end
18
+
19
+ config.around(:each) do |example|
20
+ tracer = Buildkite::TestCollector::Tracer.new
21
+
22
+ # The _buildkite prefix here is added as a safeguard against name collisions
23
+ # as we are in the main thread
24
+ Thread.current[:_buildkite_tracer] = tracer
25
+ example.run
26
+ Thread.current[:_buildkite_tracer] = nil
27
+
28
+ tracer.finalize
29
+
30
+ trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(example, history: tracer.history)
31
+ Buildkite::TestCollector.uploader.traces[example.id] = trace
32
+ end
33
+ end
34
+
35
+ Buildkite::TestCollector.enable_tracing!
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "time"
5
+
6
+ module Buildkite::TestCollector
7
+ class Logger < ::Logger
8
+ class Formatter < ::Logger::Formatter
9
+ def call(severity, time, _program, message)
10
+ "#{time.utc.iso8601(9)} pid=#{::Process.pid} tid=#{::Thread.current.object_id} #{severity}: #{message}\n"
11
+ end
12
+ end
13
+
14
+ def initialize(*args, **kwargs)
15
+ super
16
+ self.formatter = Buildkite::TestCollector.log_formatter
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buildkite::TestCollector::MinitestPlugin
4
+ class Reporter < Minitest::StatisticsReporter
5
+ def initialize(io, options)
6
+ super
7
+ @io = io
8
+ @options = options
9
+ end
10
+
11
+ def record(result)
12
+ super
13
+
14
+ if trace = Buildkite::TestCollector.uploader.traces[result.source_location]
15
+ Buildkite::TestCollector.session&.write_result(trace)
16
+ end
17
+ end
18
+
19
+ def report
20
+ super
21
+
22
+ if Buildkite::TestCollector.session.present?
23
+ examples_count = {
24
+ examples: count,
25
+ failed: failures,
26
+ pending: skips,
27
+ errors_outside_examples: 0, # Minitest does not report this
28
+ }
29
+
30
+ Buildkite::TestCollector.session.close(examples_count)
31
+ end
32
+ end
33
+ end
34
+ end