Skip to content

Commit

Permalink
Task to update gemspec dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Nov 22, 2024
1 parent 791f9db commit a0d4f13
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-latest-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: bundle install

- name: Update latest
run: bundle exec rake edge:update
run: bundle exec rake edge:gemspec edge:update

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ namespace :test do
spec_arguments = args.task_args

candidates = spec_metadata.select do |appraisal_group, rubies|
if RUBY_PLATFORM == 'java'
# Rails 4.x is not supported on JRuby 9.2 (which is RUBY_VERSION 2.5)
next false if ruby_runtime == 'jruby-9.2' && appraisal_group.start_with?('rails4')
# Exceptions:
# Rails 4.x is not supported on JRuby 9.2 (which is RUBY_VERSION 2.5)
next false if ruby_runtime == 'jruby-9.2' && appraisal_group.start_with?('rails4')

rubies.include?("✅ #{ruby_version}") && rubies.include?('✅ jruby')
else
rubies.include?("✅ #{ruby_version}")
end
RuntimeMatcher.match?(rubies)
end

candidates.each do |appraisal_group, _|
Expand Down
63 changes: 24 additions & 39 deletions tasks/edge.rake
Original file line number Diff line number Diff line change
@@ -1,74 +1,59 @@
require 'open3'

require_relative 'appraisal_conversion'
require_relative 'runtime_matcher'

# rubocop:disable Metrics/BlockLength
namespace :edge do
desc 'Update all the groups from the matrix'
task :update do |_t, args|
ruby_version = RUBY_VERSION[0..2]
allowlist = {
'stripe' => 'stripe',
'elasticsearch' => 'elasticsearch',
'opensearch' => 'opensearch-ruby',
'rack' => 'rack',
# Add more integrations here, when they are extracted to its own isolated group
}

allowlist = allowlist.slice(*args.extras) if args.extras.any?
desc 'Update all the groups with gemspec dependencies'
task :gemspec do |_t, _args|
candidates = Set.new

allowlist.each do |integration, gem|
candidates = TEST_METADATA.fetch(integration).select do |_, rubies|
if RUBY_PLATFORM == 'java'
rubies.include?("✅ #{ruby_version}") && rubies.include?('✅ jruby')
else
rubies.include?("✅ #{ruby_version}")
end
TEST_METADATA.each do |_, metadata|
metadata.each do |group, rubies|
candidates << group if RuntimeMatcher.match?(rubies)
end
end

candidates.each do |group, _|
gemfile = AppraisalConversion.to_bundle_gemfile(group)
gemspec_runtime_dependencies = Gem::Specification.load('datadog.gemspec').dependencies

Bundler.with_unbundled_env do
puts "======== Updating #{integration} in #{gemfile} ========\n"
output, = Open3.capture2e({ 'BUNDLE_GEMFILE' => gemfile.to_s }, "bundle lock --update=#{gem}")
candidates.each do |group|
next if group.empty?

puts output
end
gemfile = AppraisalConversion.to_bundle_gemfile(group)

Bundler.with_unbundled_env do
output, = Open3.capture2e(
{ 'BUNDLE_GEMFILE' => gemfile.to_s },
"bundle lock --update=#{gemspec_runtime_dependencies.map(&:name).join(' ')}"
)

puts output
end
end
end

desc 'Update the `latest` group from the matrix'
task :latest do |_t, args|
ruby_version = RUBY_VERSION[0..2]
desc 'Update groups with targeted dependencies'
task :update do |_t, args|
allowlist = {
'stripe' => 'stripe',
'elasticsearch' => 'elasticsearch',
'opensearch' => 'opensearch-ruby',
'rack' => 'rack',
# Add more integrations here, when hey are extracted to its own isolated group
# Add more integrations here, when they are extracted to its own isolated group
}

allowlist = allowlist.slice(*args.extras) if args.extras.any?

allowlist.each do |integration, gem|
candidates = TEST_METADATA.fetch(integration).select do |_, rubies|
if RUBY_PLATFORM == 'java'
rubies.include?("✅ #{ruby_version}") && rubies.include?('✅ jruby')
else
rubies.include?("✅ #{ruby_version}")
end
RuntimeMatcher.match?(rubies)
end

candidates.each do |group, _|
# ONLY pick the latest group
next unless group.end_with?('-latest')

gemfile = AppraisalConversion.to_bundle_gemfile(group)

Bundler.with_unbundled_env do
puts "======== Updating #{integration} in #{gemfile} ========\n"
output, = Open3.capture2e({ 'BUNDLE_GEMFILE' => gemfile.to_s }, "bundle lock --update=#{gem}")

puts output
Expand Down
12 changes: 12 additions & 0 deletions tasks/runtime_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This module translates our custom mapping between appraisal and bundler.
module RuntimeMatcher
def self.match?(rubies)
ruby_version = RUBY_VERSION[0..2]

if RUBY_PLATFORM == 'java'
rubies.include?("✅ #{ruby_version}") && rubies.include?('✅ jruby')
else
rubies.include?("✅ #{ruby_version}")
end
end
end

0 comments on commit a0d4f13

Please sign in to comment.