-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add supported versions workflow #4210
base: master
Are you sure you want to change the base?
Changes from 14 commits
3f4560a
1980b6f
1b2986e
5bee321
b2818a9
53b807f
df5640a
2b15400
112db1f
3b5aae2
4ada6cf
b4526e2
d44249b
514be2c
65aee38
6fb1de7
3b8cff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
require 'pathname' | ||
require 'rubygems' | ||
require 'json' | ||
require 'bundler' | ||
|
||
lib = File.expand_path('lib', __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'datadog' | ||
|
||
def parse_gemfiles(directory = 'gemfiles/') | ||
min_gems = { 'ruby' => {}, 'jruby' => {} } | ||
max_gems = { 'ruby' => {}, 'jruby' => {} } | ||
|
||
gemfiles = Dir.glob(File.join(directory, '*')) | ||
gemfiles.each do |gemfile_name| | ||
runtime = File.basename(gemfile_name).split('_').first # ruby or jruby | ||
next unless %w[ruby jruby].include?(runtime) | ||
# parse the gemfile | ||
if gemfile_name.end_with?(".gemfile") | ||
process_gemfile(gemfile_name, runtime, min_gems, max_gems) | ||
elsif gemfile_name.end_with?('.gemfile.lock') | ||
process_lockfile(gemfile_name, runtime, min_gems, max_gems) | ||
end | ||
end | ||
|
||
[min_gems['ruby'], min_gems['jruby'], max_gems['ruby'], max_gems['jruby']] | ||
end | ||
|
||
def process_gemfile(gemfile_name, runtime, min_gems, max_gems) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationAvoid top-level methods definition. Organize methods in modules/classes. (...read more)This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse. Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope. To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing |
||
begin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Code Quality ViolationUse the method's implicit 'begin' instead of adding an explicit 'begin' block (...read more)In Ruby, every method has an implicit The importance of this rule lies in the practice of writing clean, maintainable, and efficient code. Unnecessary code can lead to confusion for other developers, making the codebase more difficult to understand and maintain. It can also lead to potential bugs or performance issues. To adhere to this rule, ensure that you do not use an explicit |
||
definition = Bundler::Definition.build(gemfile_name, nil, nil) | ||
definition.dependencies.each do |dependency| | ||
gem_name = dependency.name | ||
version = dependency.requirement.to_s | ||
update_gem_versions(runtime, gem_name, version, min_gems, max_gems) | ||
end | ||
rescue Bundler::GemfileError => e | ||
puts "Error reading Gemfile: #{e.message}" | ||
end | ||
end | ||
|
||
def process_lockfile(gemfile_name, runtime, min_gems, max_gems) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationAvoid top-level methods definition. Organize methods in modules/classes. (...read more)This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse. Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope. To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing |
||
lockfile_contents = File.read(gemfile_name) | ||
parser = Bundler::LockfileParser.new(lockfile_contents) | ||
parser.specs.each do |spec| | ||
gem_name = spec.name | ||
version = spec.version.to_s | ||
update_gem_versions(runtime, gem_name, version, min_gems, max_gems) | ||
end | ||
end | ||
|
||
def update_gem_versions(runtime, gem_name, version, min_gems, max_gems) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationAvoid top-level methods definition. Organize methods in modules/classes. (...read more)This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse. Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope. To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing |
||
return unless version_valid?(version) | ||
|
||
gem_version = Gem::Version.new(version) | ||
|
||
# Update minimum gems | ||
if min_gems[runtime][gem_name].nil? || gem_version < Gem::Version.new(min_gems[runtime][gem_name]) | ||
min_gems[runtime][gem_name] = version | ||
end | ||
|
||
# Update maximum gems | ||
if max_gems[runtime][gem_name].nil? || gem_version > Gem::Version.new(max_gems[runtime][gem_name]) | ||
max_gems[runtime][gem_name] = version | ||
end | ||
end | ||
|
||
|
||
|
||
# Helper: Validate the version format | ||
def version_valid?(version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationAvoid top-level methods definition. Organize methods in modules/classes. (...read more)This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse. Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope. To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing |
||
return false if version.nil? | ||
|
||
version = version.to_s.strip | ||
|
||
return false if version.empty? | ||
|
||
# Ensure it's a valid Gem::Version | ||
begin | ||
Gem::Version.new(version) | ||
true | ||
rescue ArgumentError | ||
false | ||
end | ||
end | ||
|
||
def get_integration_names(directory = 'lib/datadog/tracing/contrib/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Code Quality ViolationAvoid top-level methods definition. Organize methods in modules/classes. (...read more)This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse. Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope. To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing |
||
Datadog::Tracing::Contrib::REGISTRY.map{ |i| i.name.to_s } | ||
end | ||
|
||
# TODO: The gem information should reside in the integration declaration instead of here. | ||
|
||
mapping = { | ||
quinna-h marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some that I don't see and I don't think have a clear automation path that we could potentially just hardcode in:
Just went through the list of them here: https://docs.datadoghq.com/tracing/trace_collection/compatibility/ruby/#integrations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. left comments about these on the generated PR: #4236 |
||
"action_mailer" => "actionmailer", | ||
"opensearch" => "opensearch-ruby", | ||
"concurrent_ruby" => "concurrent-ruby", | ||
"action_view" => "actionview", | ||
"action_cable" => "actioncable", | ||
"active_record" => "activerecord", | ||
"mongodb" => "mongo", | ||
"rest_client" => "rest-client", | ||
"active_support" => "activesupport", | ||
"action_pack" => "actionpack", | ||
"active_job" => "activejob", | ||
"httprb" => "http", | ||
"kafka" => "ruby-kafka", | ||
"presto" => "presto-client", | ||
"aws" => "aws-sdk-core" | ||
} | ||
|
||
excluded = ["configuration", "propagation", "utils"] | ||
min_gems_ruby, min_gems_jruby, max_gems_ruby, max_gems_jruby = parse_gemfiles("gemfiles/") | ||
integrations = get_integration_names('lib/datadog/tracing/contrib/') | ||
|
||
integration_json_mapping = {} | ||
|
||
integrations.each do |integration| | ||
if excluded.include?(integration) | ||
next | ||
end | ||
integration_name = mapping[integration] || integration | ||
|
||
min_version_jruby = min_gems_jruby[integration_name] | ||
min_version_ruby = min_gems_ruby[integration_name] | ||
max_version_jruby = max_gems_jruby[integration_name] | ||
max_version_ruby = max_gems_ruby[integration_name] | ||
|
||
# mapping jruby, ruby | ||
integration_json_mapping[integration] = [min_version_ruby, max_version_ruby, min_version_jruby, max_version_jruby] | ||
integration_json_mapping.replace(integration_json_mapping.sort.to_h) | ||
end | ||
|
||
File.write("gem_output.json", JSON.pretty_generate(integration_json_mapping)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'json' | ||
|
||
# Input and output file names | ||
input_file = 'gem_output.json' | ||
output_file = 'integration_versions.md' | ||
|
||
# Read JSON data from the input file | ||
data = JSON.parse(File.read(input_file)) | ||
|
||
# Prepare the Markdown content | ||
comment = "# Integrations\n\n" | ||
header = "| Integration | Ruby Min | Ruby Max | JRuby Min | JRuby Max |\n" | ||
separator = "|-------------|----------|-----------|----------|----------|\n" | ||
rows = data.map do |integration_name, versions| | ||
ruby_min, ruby_max, jruby_min, jruby_max = versions.map { |v| v || "None" } | ||
"| #{integration_name} | #{ruby_min} | #{ruby_max} | #{jruby_min} | #{jruby_max} |" | ||
end | ||
|
||
# Write the Markdown file | ||
File.open(output_file, 'w') do |file| | ||
file.puts comment | ||
file.puts header | ||
file.puts separator | ||
rows.each { |row| file.puts row } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: "Generate Supported Versions" | ||
|
||
on: | ||
push: | ||
branches: | ||
- quinna.halim/add-supported-versions-table | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to self: remove before merge |
||
workflow_dispatch: | ||
|
||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true # runs bundle install | ||
ruby-version: "3.3" | ||
|
||
- name: Update latest | ||
run: bundle exec ruby .github/scripts/find_gem_version_bounds.rb | ||
|
||
- name: Generate versions table | ||
run: ruby .github/scripts/generate_table_versions.rb | ||
|
||
- run: git diff | ||
|
||
- name: Create Pull Request | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
token: ${{ secrets.GHA_PAT }} | ||
branch: auto-generate/update-supported-versions | ||
title: '[🤖] Update Supported Versions' | ||
base: master | ||
labels: dev/internal, integrations | ||
commit-message: "Test creating supported versions" | ||
delete-branch: true | ||
body: | | ||
This is a PR to update the table for supported integration versions. | ||
Workflow run: [Generate Supported Versions](https://github.com/DataDog/dd-trace-rb/actions/workflows/generate-supported-versions.yml) | ||
This should be tied to tracer releases, or triggered manually. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Code Quality Violation
Avoid top-level methods definition. Organize methods in modules/classes. (...read more)
This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.
Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.
To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing
def some_method; end
, you should writeclass SomeClass def some_method; end end
. This not only adheres to the rule but also improves the readability and maintainability of your code.