buildkite-test_collector 2.7.2 → 2.9.0

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: 031c438a0a80bcd10c351184efb4749618f5bf65d94518454cfe4d105c3d0f05
4
- data.tar.gz: aeb85765c74bd2e59c4daa11270fcd807aa4964f9eea985ae0587075bdb437d8
3
+ metadata.gz: 468ad8ce641432cc7a1112d1f80396a4f54e9d63a566aa7f240d485969855686
4
+ data.tar.gz: 8348dc3fac0a7e57b0543da3870fbc89cdef8b0e1662c439eaea8c7d2a685210
5
5
  SHA512:
6
- metadata.gz: 38352feb0b55450da89472f06f883bd565b4ee6ac4c7f14ff8dfb7456621626c404868d25c7348676db2b288948f65bad26b6d40308097800583960150f0f4b8
7
- data.tar.gz: a7500ee72f134530e3b7254dfe3391604edea02937d2e762349e8ea242be0d55c46c48d3563fdfe909aeee9475575fc4815a7e36bd3105188e8fd36cb1aa8b9b
6
+ metadata.gz: 70baa9565cb411b56888f1e72048d554e87dc6d8ee76c7dd1cc3d67e943801f9133e27d883a5d7da74677b61d73c2c8258385a02aa4c997f98471d3d1157af06
7
+ data.tar.gz: c8a34a8fd8c6554c59a66812d41cc747cc5ffae27b4f651c4ca58c6cb44c81ec9f747eeb82ac061897e11c555053404be500414055c0881adafb33272ba1c511
@@ -0,0 +1,18 @@
1
+ agents:
2
+ queue: hosted
3
+
4
+ steps:
5
+ - block: "OK to release?"
6
+
7
+ - command: ".buildkite/steps/release-gem"
8
+ label: ":rubygems:"
9
+ if: build.tag != null
10
+ plugins:
11
+ - rubygems-oidc#v0.2.0:
12
+ role: "rg_oidc_akr_fy1x4px4yjwd1rdhkkda"
13
+ - docker#v5.12.0:
14
+ image: "ruby:3.4"
15
+ environment:
16
+ - GEM_HOST_API_KEY
17
+ - BUILDKITE_TAG
18
+
@@ -0,0 +1,56 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+
5
+ if [ -z "${GEM_HOST_API_KEY}" ]; then
6
+ echo "GEM_HOST_API_KEY environment variable not found"
7
+ exit 1
8
+ fi
9
+
10
+ if [ -z "${BUILDKITE_TAG}" ]; then
11
+ echo "BUILDKITE_TAG environment variable not found"
12
+ exit 1
13
+ fi
14
+
15
+ cd $(dirname $0)/../..
16
+
17
+ echo "--- Inspecting tag and version"
18
+
19
+ echo "BUILDKITE_TAG: ${BUILDKITE_TAG}"
20
+
21
+ if [[ ! "${BUILDKITE_TAG}" == v* ]]; then
22
+ echo "We will only try to publish to rubygems when the tag starts with 'v'"
23
+ exit 1
24
+ fi
25
+
26
+ VERSION=$(echo "${BUILDKITE_TAG}" | sed "s/^v//")
27
+ GEM_FILENAME="buildkite-test_collector-${VERSION}.gem"
28
+
29
+ echo "Version to release: ${VERSION}"
30
+
31
+ echo "--- Building gem"
32
+
33
+ gem build buildkite-test_collector.gemspec
34
+
35
+ if [ ! -f "${GEM_FILENAME}" ]; then
36
+ echo
37
+ echo "ERROR: Expected compiled gem to be '${GEM_FILENAME}' but file not found"
38
+ echo "Does the gemspec specify version '${BUILDKITE_TAG}'?"
39
+ echo
40
+ echo "Gem files found:"
41
+ echo
42
+ ls *.gem
43
+ echo
44
+ exit 1
45
+ fi
46
+
47
+ echo "--- Check if version already exists on rubygems.org"
48
+
49
+ if [ $(curl -s -o /dev/null -w "%{http_code}" https://rubygems.org/api/v2/rubygems/buildkite-test_collector/versions/${VERSION}.json) == "200" ]; then
50
+ echo "Gem version ${VERSION} already found on rubygems, skipping release"
51
+ exit 1
52
+ fi
53
+
54
+ echo "--- publish gem"
55
+
56
+ gem push "${GEM_FILENAME}"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v2.9.0
4
+
5
+ * `Buildkite::TestCollector.tag_execution(key, value)` by @pda in https://github.com/buildkite/test-collector-ruby/pull/240
6
+
7
+ **Full Changelog**: https://github.com/buildkite/test-collector-ruby/compare/v2.8.0...v2.9.0
8
+
9
+ ## v2.8.0
10
+
11
+ * Buildkite::TestCollector.tags: specify tags for all executions by @pda in https://github.com/buildkite/test-collector-ruby/pull/235
12
+ * Add Ruby 3.4 to Buildkite build matrix by @gchan in https://github.com/buildkite/test-collector-ruby/pull/236
13
+
14
+ **Full Changelog**: https://github.com/buildkite/test-collector-ruby/compare/v2.7.2...v2.8.0
15
+
3
16
  ## v2.7.2
4
17
 
5
18
  - Fixes RSpec library hook bug introduced in v2.7.1 #230 - @malclocke
data/Gemfile.lock CHANGED
@@ -1,37 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buildkite-test_collector (2.7.2)
4
+ buildkite-test_collector (2.9.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (7.0.7.2)
10
- concurrent-ruby (~> 1.0, >= 1.0.2)
9
+ activesupport (8.0.1)
10
+ base64
11
+ benchmark (>= 0.3)
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.3.1)
14
+ connection_pool (>= 2.2.5)
15
+ drb
11
16
  i18n (>= 1.6, < 2)
17
+ logger (>= 1.4.2)
12
18
  minitest (>= 5.1)
13
- tzinfo (~> 2.0)
14
- concurrent-ruby (1.2.2)
15
- diff-lcs (1.4.4)
16
- i18n (1.14.1)
19
+ securerandom (>= 0.3)
20
+ tzinfo (~> 2.0, >= 2.0.5)
21
+ uri (>= 0.13.1)
22
+ base64 (0.2.0)
23
+ benchmark (0.4.0)
24
+ bigdecimal (3.1.9)
25
+ concurrent-ruby (1.3.5)
26
+ connection_pool (2.5.0)
27
+ diff-lcs (1.5.1)
28
+ drb (2.2.1)
29
+ i18n (1.14.7)
17
30
  concurrent-ruby (~> 1.0)
18
- minitest (5.19.0)
19
- rake (13.0.6)
20
- rspec (3.10.0)
21
- rspec-core (~> 3.10.0)
22
- rspec-expectations (~> 3.10.0)
23
- rspec-mocks (~> 3.10.0)
24
- rspec-core (3.10.1)
25
- rspec-support (~> 3.10.0)
26
- rspec-expectations (3.10.1)
31
+ logger (1.6.5)
32
+ minitest (5.25.4)
33
+ rake (13.2.1)
34
+ rspec (3.13.0)
35
+ rspec-core (~> 3.13.0)
36
+ rspec-expectations (~> 3.13.0)
37
+ rspec-mocks (~> 3.13.0)
38
+ rspec-core (3.13.2)
39
+ rspec-support (~> 3.13.0)
40
+ rspec-expectations (3.13.3)
27
41
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.10.0)
29
- rspec-mocks (3.10.2)
42
+ rspec-support (~> 3.13.0)
43
+ rspec-mocks (3.13.2)
30
44
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.10.0)
32
- rspec-support (3.10.3)
45
+ rspec-support (~> 3.13.0)
46
+ rspec-support (3.13.2)
47
+ securerandom (0.4.1)
33
48
  tzinfo (2.0.6)
34
49
  concurrent-ruby (~> 1.0)
50
+ uri (1.0.2)
35
51
 
36
52
  PLATFORMS
37
53
  ruby
data/README.md CHANGED
@@ -131,14 +131,15 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/buildk
131
131
 
132
132
  1. Bump the version in `version.rb` and run `bundle` to update the `Gemfile.lock`.
133
133
  1. Update the CHANGELOG.md with your new version and a description of your changes.
134
- 1. Git tag your changes and push
135
- ```
136
- git tag v.x.x.x
137
- git push --tags
138
- ```
134
+
139
135
  Once your PR is merged to `main`:
140
136
 
141
- 1. Run `rake release` from `main`.
137
+ 1. Git tag the merge commit and push
138
+ ```
139
+ git tag vX.X.X
140
+ git push origin vX.X.X
141
+ ```
142
+ 1. Visit the [release pipeline](https://buildkite.com/buildkite/test-collector-ruby-release) to unblock it and confirm the new version is pushed to rubygems.org
142
143
  1. Create a [new release in github](https://github.com/buildkite/test-collector-ruby/releases).
143
144
 
144
145
  ## 📜 MIT License
data/buildkite.yaml CHANGED
@@ -4,6 +4,7 @@ agents:
4
4
  steps:
5
5
  - label: ":rspec: Tests :ruby: {{matrix}}"
6
6
  command:
7
+ - "gem install bundler:2.3.25"
7
8
  - "bundle"
8
9
  - "bundle exec rake"
9
10
  plugins:
@@ -11,6 +12,7 @@ steps:
11
12
  image: "public.ecr.aws/docker/library/ruby:{{matrix}}"
12
13
  matrix:
13
14
  - "latest"
15
+ - "3.4"
14
16
  - "3.3"
15
17
  - "3.2"
16
18
  - "3.1"
@@ -4,19 +4,18 @@ require "net/http"
4
4
 
5
5
  module Buildkite::TestCollector
6
6
  class HTTPClient
7
- attr :authorization_header
8
- def initialize(url)
7
+ def initialize(url:, api_token:)
9
8
  @url = url
10
- @authorization_header = "Token token=\"#{Buildkite::TestCollector.api_token}\""
9
+ @api_token = api_token
11
10
  end
12
11
 
13
- def post_json(data)
14
- contact_uri = URI.parse(url)
12
+ def post_upload(data:, run_env:, tags:)
13
+ endpoint_uri = URI.parse(url)
15
14
 
16
- http = Net::HTTP.new(contact_uri.host, contact_uri.port)
17
- http.use_ssl = contact_uri.scheme == "https"
15
+ http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
16
+ http.use_ssl = endpoint_uri.scheme == "https"
18
17
 
19
- contact = Net::HTTP::Post.new(contact_uri.path, {
18
+ request = Net::HTTP::Post.new(endpoint_uri.path, {
20
19
  "Authorization" => authorization_header,
21
20
  "Content-Type" => "application/json",
22
21
  "Content-Encoding" => "gzip",
@@ -25,7 +24,8 @@ module Buildkite::TestCollector
25
24
  data_set = data.map(&:as_hash)
26
25
 
27
26
  body = {
28
- run_env: Buildkite::TestCollector::CI.env,
27
+ run_env: run_env,
28
+ tags: tags,
29
29
  format: "json",
30
30
  data: data_set
31
31
  }.to_json
@@ -36,9 +36,9 @@ module Buildkite::TestCollector
36
36
  writer.write(body)
37
37
  writer.close
38
38
 
39
- contact.body = compressed_body.string
39
+ request.body = compressed_body.string
40
40
 
41
- response = http.request(contact)
41
+ response = http.request(request)
42
42
 
43
43
  if response.is_a?(Net::HTTPSuccess)
44
44
  response
@@ -48,21 +48,25 @@ module Buildkite::TestCollector
48
48
  end
49
49
 
50
50
  def metadata
51
- contact_uri = URI.parse("#{url}/metadata")
51
+ endpoint_uri = URI.parse("#{url}/metadata")
52
52
 
53
- http = Net::HTTP.new(contact_uri.host, contact_uri.port)
54
- http.use_ssl = contact_uri.scheme == "https"
53
+ http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
54
+ http.use_ssl = endpoint_uri.scheme == "https"
55
55
 
56
- contact = Net::HTTP::Get.new(contact_uri.path, {
56
+ request = Net::HTTP::Get.new(endpoint_uri.path, {
57
57
  "Authorization" => authorization_header,
58
58
  "Content-Type" => "application/json"
59
59
  })
60
60
 
61
- http.request(contact)
61
+ http.request(request)
62
62
  end
63
63
 
64
64
  private
65
65
 
66
- attr :url
66
+ attr_reader :url
67
+
68
+ def authorization_header
69
+ "Token token=\"#{@api_token}\""
70
+ end
67
71
  end
68
72
  end
@@ -18,21 +18,27 @@ RSpec.configure do |config|
18
18
  min_duration: Buildkite::TestCollector.trace_min_duration,
19
19
  )
20
20
 
21
- # The _buildkite prefix here is added as a safeguard against name collisions
22
- # as we are in the main thread
21
+ tags = {}
22
+
23
+ # _buildkite prefix reduces chance of collisions in this almost-global (per-fiber) namespace.
23
24
  Thread.current[:_buildkite_tracer] = tracer
24
- # It's important to use begin/ensure here, because otherwise if other hooks fail,
25
- # the cleanup code won't run, meaning we will miss some data.
26
- #
27
- # Having said that, this behavior isn't documented by RSpec.
25
+ Thread.current[:_buildkite_tags] = tags
26
+
27
+ # example.run can raise errors (including from other middleware/hooks) so clean up in `ensure`.
28
28
  begin
29
29
  example.run
30
30
  ensure
31
31
  Thread.current[:_buildkite_tracer] = nil
32
+ Thread.current[:_buildkite_tags] = nil
32
33
 
33
34
  tracer.finalize
34
35
 
35
- trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(example, history: tracer.history)
36
+ trace = Buildkite::TestCollector::RSpecPlugin::Trace.new(
37
+ example,
38
+ history: tracer.history,
39
+ tags: tags,
40
+ )
41
+
36
42
  Buildkite::TestCollector.uploader.traces[example.id] = trace
37
43
  end
38
44
  end
@@ -5,6 +5,7 @@ module Buildkite::TestCollector::MinitestPlugin
5
5
  attr_accessor :example
6
6
  attr_writer :failure_reason, :failure_expanded
7
7
  attr_reader :history
8
+ attr_reader :tags
8
9
 
9
10
  RESULT_CODES = {
10
11
  '.' => 'passed',
@@ -15,9 +16,10 @@ module Buildkite::TestCollector::MinitestPlugin
15
16
 
16
17
  FILE_PATH_REGEX = /^(.*?\.(rb|feature))/
17
18
 
18
- def initialize(example, history:)
19
+ def initialize(example, history:, tags: nil)
19
20
  @example = example
20
21
  @history = history
22
+ @tags = tags
21
23
  end
22
24
 
23
25
  def result
@@ -38,6 +40,7 @@ module Buildkite::TestCollector::MinitestPlugin
38
40
  failure_reason: failure_reason,
39
41
  failure_expanded: failure_expanded,
40
42
  history: history,
43
+ tags: tags,
41
44
  ).select { |_, value| !value.nil? }
42
45
  end
43
46
 
@@ -14,18 +14,29 @@ module Buildkite::TestCollector::MinitestPlugin
14
14
  min_duration: Buildkite::TestCollector.trace_min_duration,
15
15
  )
16
16
 
17
- # The _buildkite prefix here is added as a safeguard against name collisions
18
- # as we are in the main thread
17
+ tags = {}
18
+
19
+ # _buildkite prefix reduces chance of collisions in this almost-global (per-fiber) namespace.
19
20
  Thread.current[:_buildkite_tracer] = tracer
21
+ Thread.current[:_buildkite_tags] = tags
20
22
  end
21
23
 
22
24
  def after_teardown
23
25
  tracer = Thread.current[:_buildkite_tracer]
26
+ tags = Thread.current[:_buildkite_tags]
27
+
28
+ Thread.current[:_buildkite_tracer] = nil
29
+ Thread.current[:_buildkite_tags] = nil
30
+
24
31
  if !tracer.nil?
25
- Thread.current[:_buildkite_tracer] = nil
26
32
  tracer.finalize
27
33
 
28
- trace = Buildkite::TestCollector::MinitestPlugin::Trace.new(self, history: tracer.history)
34
+ trace = Buildkite::TestCollector::MinitestPlugin::Trace.new(
35
+ self,
36
+ history: tracer.history,
37
+ tags: tags,
38
+ )
39
+
29
40
  Buildkite::TestCollector.uploader.traces[trace.source_location] = trace
30
41
  end
31
42
 
@@ -4,14 +4,16 @@ module Buildkite::TestCollector::RSpecPlugin
4
4
  class Trace
5
5
  attr_accessor :example, :failure_reason, :failure_expanded
6
6
  attr_reader :history
7
+ attr_reader :tags
7
8
 
8
9
  FILE_PATH_REGEX = /^(.*?\.(rb|feature))/
9
10
 
10
- def initialize(example, history:, failure_reason: nil, failure_expanded: [])
11
+ def initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil)
11
12
  @example = example
12
13
  @history = history
13
14
  @failure_reason = failure_reason
14
15
  @failure_expanded = failure_expanded
16
+ @tags = tags
15
17
  end
16
18
 
17
19
  def result
@@ -32,6 +34,7 @@ module Buildkite::TestCollector::RSpecPlugin
32
34
  failure_reason: failure_reason,
33
35
  failure_expanded: failure_expanded,
34
36
  history: history,
37
+ tags: tags,
35
38
  ).select { |_, value| !value.nil? }
36
39
  end
37
40
 
@@ -36,16 +36,23 @@ module Buildkite::TestCollector
36
36
  def self.upload(data)
37
37
  return false unless Buildkite::TestCollector.api_token
38
38
 
39
- http = Buildkite::TestCollector::HTTPClient.new(Buildkite::TestCollector.url)
39
+ http = Buildkite::TestCollector::HTTPClient.new(
40
+ url: Buildkite::TestCollector.url,
41
+ api_token: Buildkite::TestCollector.api_token,
42
+ )
40
43
 
41
44
  Thread.new do
42
45
  begin
43
46
  upload_attempts ||= 0
44
- http.post_json(data)
47
+ http.post_upload(
48
+ data: data,
49
+ run_env: Buildkite::TestCollector::CI.env,
50
+ tags: Buildkite::TestCollector.tags,
51
+ )
52
+
45
53
  rescue *Buildkite::TestCollector::Uploader::RETRYABLE_UPLOAD_ERRORS => e
46
- if (upload_attempts += 1) < MAX_UPLOAD_ATTEMPTS
47
- retry
48
- end
54
+ retry if (upload_attempts += 1) < MAX_UPLOAD_ATTEMPTS
55
+
49
56
  rescue StandardError => e
50
57
  $stderr.puts e
51
58
  $stderr.puts "#{Buildkite::TestCollector::NAME} #{Buildkite::TestCollector::VERSION} experienced an error when sending your data, you may be missing some executions for this run."
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Buildkite
4
4
  module TestCollector
5
- VERSION = "2.7.2"
5
+ VERSION = "2.9.0"
6
6
  NAME = "buildkite-test_collector"
7
7
  end
8
8
  end
@@ -36,17 +36,19 @@ module Buildkite
36
36
  attr_accessor :tracing_enabled
37
37
  attr_accessor :artifact_path
38
38
  attr_accessor :env
39
+ attr_accessor :tags
39
40
  attr_accessor :batch_size
40
41
  attr_accessor :trace_min_duration
41
42
  attr_accessor :span_filters
42
43
  end
43
44
 
44
- def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {})
45
+ def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {}, tags: {})
45
46
  self.api_token = (token || ENV["BUILDKITE_ANALYTICS_TOKEN"])&.strip
46
47
  self.url = url || DEFAULT_URL
47
48
  self.tracing_enabled = tracing_enabled
48
49
  self.artifact_path = artifact_path
49
50
  self.env = env
51
+ self.tags = tags
50
52
  self.batch_size = ENV.fetch("BUILDKITE_ANALYTICS_UPLOAD_BATCH_SIZE") { DEFAULT_UPLOAD_BATCH_SIZE }.to_i
51
53
 
52
54
  trace_min_ms_string = ENV["BUILDKITE_ANALYTICS_TRACE_MIN_MS"]
@@ -75,6 +77,18 @@ module Buildkite
75
77
  tracer&.leave
76
78
  end
77
79
 
80
+ # Set a key=value tag on the current test execution.
81
+ def self.tag_execution(key, value)
82
+ tags = Thread.current[:_buildkite_tags]
83
+ raise "_buildkite_tags not available" unless tags
84
+
85
+ unless key.is_a?(String) && value.is_a?(String)
86
+ raise ArgumentError, "tag key and value expected string"
87
+ end
88
+
89
+ tags[key] = value
90
+ end
91
+
78
92
  def self.enable_tracing!
79
93
  return unless self.tracing_enabled
80
94
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-test_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-16 00:00:00.000000000 Z
10
+ date: 2025-02-21 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -52,13 +51,14 @@ dependencies:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
53
  version: '3.10'
55
- description:
56
54
  email:
57
55
  - support+analytics@buildkite.com
58
56
  executables: []
59
57
  extensions: []
60
58
  extra_rdoc_files: []
61
59
  files:
60
+ - ".buildkite/pipeline.release.yml"
61
+ - ".buildkite/steps/release-gem"
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
64
  - CHANGELOG.md
@@ -99,7 +99,6 @@ licenses:
99
99
  metadata:
100
100
  homepage_uri: https://github.com/buildkite/test-collector-ruby
101
101
  source_code_uri: https://github.com/buildkite/test-collector-ruby
102
- post_install_message:
103
102
  rdoc_options: []
104
103
  require_paths:
105
104
  - lib
@@ -114,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
113
  - !ruby/object:Gem::Version
115
114
  version: '0'
116
115
  requirements: []
117
- rubygems_version: 3.5.11
118
- signing_key:
116
+ rubygems_version: 3.6.2
119
117
  specification_version: 4
120
118
  summary: Track test executions and report to Buildkite Test Engine
121
119
  test_files: []