diff --git a/exe/ddcirb b/exe/ddcirb index 2575638e..f91a0bc2 100755 --- a/exe/ddcirb +++ b/exe/ddcirb @@ -2,4 +2,6 @@ require "datadog/ci/cli/cli" -Datadog::CI::CLI.exec(ARGV.first) +command = ARGV.shift + +Datadog::CI::CLI.exec(command, ARGV) diff --git a/lib/datadog/ci/cli/cli.rb b/lib/datadog/ci/cli/cli.rb index 99df9df9..cb061a83 100644 --- a/lib/datadog/ci/cli/cli.rb +++ b/lib/datadog/ci/cli/cli.rb @@ -1,14 +1,17 @@ require "datadog" require "datadog/ci" +require_relative "command/exec" require_relative "command/skippable_tests_percentage" require_relative "command/skippable_tests_percentage_estimate" module Datadog module CI module CLI - def self.exec(action) + def self.exec(action, args = []) case action + when "exec" + Command::Exec.new(args).exec when "skipped-tests", "skippable-tests" Command::SkippableTestsPercentage.new.exec when "skipped-tests-estimate", "skippable-tests-estimate" @@ -17,6 +20,7 @@ def self.exec(action) puts("Usage: bundle exec ddcirb [command] [options]. Available commands:") puts(" skippable-tests - calculates the exact percentage of skipped tests and prints it to stdout or file") puts(" skippable-tests-estimate - estimates the percentage of skipped tests and prints it to stdout or file") + puts(" exec YOUR_TEST_COMMAND - automatically instruments your test command with Datadog and executes it") end end end diff --git a/lib/datadog/ci/cli/command/exec.rb b/lib/datadog/ci/cli/command/exec.rb new file mode 100644 index 00000000..a8b2ae29 --- /dev/null +++ b/lib/datadog/ci/cli/command/exec.rb @@ -0,0 +1,29 @@ +require_relative "base" +require_relative "../../test_optimisation/skippable_percentage/estimator" + +module Datadog + module CI + module CLI + module Command + class Exec < Base + def initialize(args) + super() + + @args = args + end + + def exec + rubyopts = [ + "-rdatadog/ci/auto_instrument" + ] + + existing_rubyopt = ENV["RUBYOPT"] + ENV["RUBYOPT"] = existing_rubyopt ? "#{existing_rubyopt} #{rubyopts.join(" ")}" : rubyopts.join(" ") + + Kernel.exec(*@args) + end + end + end + end + end +end diff --git a/sig/datadog/ci/cli/cli.rbs b/sig/datadog/ci/cli/cli.rbs index 45e48a8f..12c5231e 100644 --- a/sig/datadog/ci/cli/cli.rbs +++ b/sig/datadog/ci/cli/cli.rbs @@ -1,7 +1,7 @@ module Datadog module CI module CLI - def self.exec: (String action) -> void + def self.exec: (String action, ?Array[String] args) -> void end end end diff --git a/sig/datadog/ci/cli/command/exec.rbs b/sig/datadog/ci/cli/command/exec.rbs new file mode 100644 index 00000000..36b0d03a --- /dev/null +++ b/sig/datadog/ci/cli/command/exec.rbs @@ -0,0 +1,15 @@ +module Datadog + module CI + module CLI + module Command + class Exec < Base + @args: Array[String] + + def initialize: (Array[String] args) -> void + + def exec: () -> void + end + end + end + end +end diff --git a/spec/datadog/ci/cli/cli_spec.rb b/spec/datadog/ci/cli/cli_spec.rb index 3d6c8011..4485ad19 100644 --- a/spec/datadog/ci/cli/cli_spec.rb +++ b/spec/datadog/ci/cli/cli_spec.rb @@ -36,6 +36,7 @@ Usage: bundle exec ddcirb [command] [options]. Available commands: skippable-tests - calculates the exact percentage of skipped tests and prints it to stdout or file skippable-tests-estimate - estimates the percentage of skipped tests and prints it to stdout or file + exec YOUR_TEST_COMMAND - automatically instruments your test command with Datadog and executes it USAGE end end