Skip to content

Commit af463bc

Browse files
chore: Fix Ruby Version Management (#1765)
* chore: Fix Ruby Version Management Prior to this change, the RUBY_REQUIREMENT file was used to keep Ruby versions in sync, however toys will not detect a change to gem since the gemspec file was unaltered. Rather than modify toys to be more flexible in this case, it will be easier to update the Ruby requirement in each gemspec using a script. The script will write out diagnostic output of the gemspecs that were changed. E.g. ```ruby $> bin/update-ruby-version 3.2 Updating Ruby version requirement to: >= 3.2 Finding gemspec files... Found 62 gemspec files to update: Updated: helpers/mysql/opentelemetry-helpers-mysql.gemspec Updated: helpers/sql/opentelemetry-helpers-sql.gemspec Updated: helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec Updated: helpers/sql-processor/opentelemetry-helpers-sql-processor.gemspec Updated: instrumentation/action_mailer/opentelemetry-instrumentation-action_mailer.gemspec ... Updated: resources/google_cloud_platform/opentelemetry-resource-detector-google_cloud_platform.gemspec Updated: sampler/xray/opentelemetry-sampler-xray.gemspec Summary: - Total files found: 62 - Successfully updated: 62 Done! All gemspecs have been updated to require Ruby >= 3.2 ``` * squash: add contributing docs * squash: work on that spelling
1 parent 61451b5 commit af463bc

File tree

66 files changed

+180
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+180
-64
lines changed

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins: rubocop-performance
22

33
AllCops:
4-
TargetRubyVersion: '3.2'
4+
TargetRubyVersion: 3.2
55
NewCops: enable
66
Exclude:
77
- Rakefile

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,35 @@ index e29acbfc..85622d25 100644
418418
(1/1) Stage this hunk [y,n,q,a,d,e,?]? y
419419
```
420420

421+
## Updating Ruby version requirements
422+
423+
To update the minimum Ruby version requirement across all gems in the repository, use the `bin/update-ruby-version` script:
424+
425+
```console
426+
# Update to Ruby 3.3 minimum
427+
bin/update-ruby-version 3.3
428+
429+
# Supports patch versions and pre-releases
430+
bin/update-ruby-version 3.2.0
431+
bin/update-ruby-version 3.4.0.alpha
432+
```
433+
434+
The script will:
435+
436+
1. Validate the version format
437+
2. Update `spec.required_ruby_version` in all gemspec files
438+
3. Show a summary of changes
439+
440+
After running the script:
441+
442+
1. Review changes with `git diff`
443+
2. Test against the new minimum Ruby version
444+
3. Update CI configurations in `.github/workflows`
445+
4. Update `.rubocop.yml` to set the `TargetRubyVersion`
446+
5. Remove any conditional logic handling Ruby versions in Appraisal files that are no longer needed
447+
6. Remove any conditional logic in test cases that are no longer needed
448+
7. Commit with a message like `chore: update minimum Ruby version to 3.3`
449+
421450
[cncf-cla]: https://identity.linuxfoundation.org/projects/cncf
422451
[github-draft]: https://github.blog/2019-02-14-introducing-draft-pull-requests/
423452
[kube-github-workflow-pr]: https://github.com/kubernetes/community/blob/master/contributors/guide/github-workflow.md#7-create-a-pull-request

bin/update-ruby-version

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Script to update Ruby version requirements in all gemspecs
5+
# Usage: bin/update-ruby-version [new_version]
6+
# Example: bin/update-ruby-version 3.3
7+
8+
require 'fileutils'
9+
require 'rubygems'
10+
11+
def update_gemspec_ruby_version(file_path, new_version)
12+
content = File.read(file_path)
13+
14+
# Pattern to match existing inline version (supports alpha/beta/pre-release versions)
15+
inline_pattern = /spec\.required_ruby_version = '>= [^']+'/
16+
replacement = "spec.required_ruby_version = '>= #{new_version}'"
17+
18+
updated_content = content.gsub(inline_pattern, replacement)
19+
File.write(file_path, updated_content)
20+
end
21+
22+
def find_gemspecs_with_ruby_requirement
23+
# Find all .gemspec files that contain inline Ruby version requirements
24+
gemspec_files = Dir.glob('**/*.gemspec')
25+
26+
gemspec_files.select do |file|
27+
content = File.read(file)
28+
# Match inline version pattern (supports alpha/beta/pre-release versions)
29+
content.match?(/spec\.required_ruby_version = '>= [^']+/)
30+
end
31+
end
32+
33+
# Main execution
34+
def main
35+
new_version = ARGV[0]
36+
37+
# Check if version parameter is provided
38+
if new_version.nil? || new_version.empty?
39+
puts 'Error: No Ruby version specified.'
40+
puts
41+
puts "Usage: #{$0} <new_ruby_version>"
42+
puts 'Examples:'
43+
puts " #{$0} 3.2"
44+
puts " #{$0} 3.3"
45+
puts " #{$0} 3.1.0"
46+
puts
47+
puts 'The version should be a valid Ruby version number (e.g., 3.2, 3.3, 3.1.0)'
48+
exit 1
49+
end
50+
51+
# Validate version format using Ruby's Gem::Version parser
52+
begin
53+
# Try to parse as a valid gem version (this will raise ArgumentError for malformed versions)
54+
Gem::Version.new(new_version)
55+
rescue ArgumentError => e
56+
puts "Error: Invalid Ruby version format '#{new_version}'"
57+
puts "Details: #{e.message}"
58+
puts
59+
puts 'The version must be a valid Ruby version number like:'
60+
puts ' - 3.2'
61+
puts ' - 3.3'
62+
puts ' - 3.1.0'
63+
puts ' - 3.4.0.alpha'
64+
puts ' - 3.3.0.beta1'
65+
puts
66+
puts "Usage: #{$0} <new_ruby_version>"
67+
exit 1
68+
end
69+
70+
puts "Updating Ruby version requirement to: >= #{new_version}"
71+
puts 'Finding gemspec files...'
72+
73+
gemspec_files = find_gemspecs_with_ruby_requirement
74+
puts "Found #{gemspec_files.length} gemspec files to update:"
75+
76+
gemspec_files.each do |file|
77+
update_gemspec_ruby_version(file, new_version)
78+
puts "Updated: #{file}"
79+
end
80+
81+
puts "\nSummary:"
82+
puts "- Total files found: #{gemspec_files.length}"
83+
puts "- Successfully updated: #{gemspec_files.length}"
84+
85+
puts "\nDone! All gemspecs have been updated to require Ruby >= #{new_version}"
86+
end
87+
88+
main if __FILE__ == $0

gemspecs/RUBY_REQUIREMENT

Lines changed: 0 additions & 1 deletion
This file was deleted.

helpers/mysql/opentelemetry-helpers-mysql.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-api', '~> 1.7'
2929
spec.add_dependency 'opentelemetry-common', '~> 0.21'

helpers/sql-obfuscation/opentelemetry-helpers-sql-obfuscation.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-common', '~> 0.21'
2929

helpers/sql-processor/opentelemetry-helpers-sql-processor.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-common', '~> 0.21'
2929

helpers/sql/opentelemetry-helpers-sql.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-api', '~> 1.7'
2929

instrumentation/action_mailer/opentelemetry-instrumentation-action_mailer.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.10'
2929

instrumentation/action_pack/opentelemetry-instrumentation-action_pack.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
2323
Dir.glob('*.md') +
2424
['LICENSE', '.yardopts']
2525
spec.require_paths = ['lib']
26-
spec.required_ruby_version = ">= #{File.read(File.expand_path('../../gemspecs/RUBY_REQUIREMENT', __dir__))}"
26+
spec.required_ruby_version = '>= 3.2'
2727

2828
spec.add_dependency 'opentelemetry-instrumentation-rack', '~> 0.29'
2929

0 commit comments

Comments
 (0)