Skip to content

Commit

Permalink
add exec CLI command for auto instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 25, 2024
1 parent 1fb8c8a commit bdb6589
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
4 changes: 3 additions & 1 deletion exe/ddcirb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

require "datadog/ci/cli/cli"

Datadog::CI::CLI.exec(ARGV.first)
command = ARGV.shift

Datadog::CI::CLI.exec(command, ARGV)
6 changes: 5 additions & 1 deletion lib/datadog/ci/cli/cli.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions lib/datadog/ci/cli/command/exec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion sig/datadog/ci/cli/cli.rbs
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions sig/datadog/ci/cli/command/exec.rbs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions spec/datadog/ci/cli/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdb6589

Please sign in to comment.