diff --git a/lib/datadog/ci/configuration/settings.rb b/lib/datadog/ci/configuration/settings.rb index 856149f8..36d6fff2 100644 --- a/lib/datadog/ci/configuration/settings.rb +++ b/lib/datadog/ci/configuration/settings.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative "../ext/settings" +require_relative "../utils/bundle" module Datadog module CI @@ -67,6 +68,20 @@ def self.add_settings!(base) o.default true end + option :itr_code_coverage_excluded_paths do |o| + o.type :array + o.env CI::Ext::Settings::ENV_ITR_CODE_COVERAGE_EXCLUDED_PATHS + o.after_set do |paths| + if paths.nil? && (bundle_path = Datadog::CI::Utils::Bundle.location) + paths = [bundle_path] + end + + paths.map do |path| + File.expand_path(path) + end + end + end + define_method(:instrument) do |integration_name, options = {}, &block| return unless enabled diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index 5e3c0034..9a326b6e 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -23,6 +23,13 @@ module Environment TAG_NODE_NAME = "ci.node.name" TAG_CI_ENV_VARS = "_dd.ci.env_vars" + POSSIBLE_BUNDLE_LOCATIONS = [ + ".bundle", + "vendor/bundle", + "vendor/cache", + "vendor/gems" + ].freeze + module_function def tags(env) diff --git a/lib/datadog/ci/ext/settings.rb b/lib/datadog/ci/ext/settings.rb index 9e2bfaf4..a2d66d5d 100644 --- a/lib/datadog/ci/ext/settings.rb +++ b/lib/datadog/ci/ext/settings.rb @@ -12,6 +12,7 @@ module Settings ENV_FORCE_TEST_LEVEL_VISIBILITY = "DD_CIVISIBILITY_FORCE_TEST_LEVEL_VISIBILITY" ENV_ITR_ENABLED = "DD_CIVISIBILITY_ITR_ENABLED" ENV_GIT_METADATA_UPLOAD_ENABLED = "DD_CIVISIBILITY_GIT_METADATA_UPLOAD_ENABLED" + ENV_ITR_CODE_COVERAGE_EXCLUDED_PATHS = "DD_CIVISIBILITY_ITR_CODE_COVERAGE_EXCLUDED_PATHS" # Source: https://docs.datadoghq.com/getting_started/site/ DD_SITE_ALLOWLIST = [ diff --git a/lib/datadog/ci/utils/bundle.rb b/lib/datadog/ci/utils/bundle.rb new file mode 100644 index 00000000..d890945a --- /dev/null +++ b/lib/datadog/ci/utils/bundle.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require_relative "../ext/environment" +require_relative "../git/local_repository" + +module Datadog + module CI + module Utils + module Bundle + def self.location + Ext::Environment::POSSIBLE_BUNDLE_LOCATIONS.each do |location| + path = File.join(Datadog::CI::Git::LocalRepository.root, location) + return path if File.directory?(path) + end + nil + end + end + end + end +end diff --git a/sig/datadog/ci/ext/environment.rbs b/sig/datadog/ci/ext/environment.rbs index 9e875937..04e04368 100644 --- a/sig/datadog/ci/ext/environment.rbs +++ b/sig/datadog/ci/ext/environment.rbs @@ -27,6 +27,8 @@ module Datadog TAG_CI_ENV_VARS: String + POSSIBLE_BUNDLE_LOCATIONS: Array[String] + PROVIDERS: ::Array[Array[String | Symbol]] def self?.tags: (untyped env) -> Hash[String, String] diff --git a/sig/datadog/ci/ext/settings.rbs b/sig/datadog/ci/ext/settings.rbs index c8847c6c..656774ca 100644 --- a/sig/datadog/ci/ext/settings.rbs +++ b/sig/datadog/ci/ext/settings.rbs @@ -9,6 +9,7 @@ module Datadog ENV_FORCE_TEST_LEVEL_VISIBILITY: String ENV_ITR_ENABLED: String ENV_GIT_METADATA_UPLOAD_ENABLED: String + ENV_ITR_CODE_COVERAGE_EXCLUDED_PATHS: String DD_SITE_ALLOWLIST: Array[String] end diff --git a/sig/datadog/ci/utils/bundle.rbs b/sig/datadog/ci/utils/bundle.rbs new file mode 100644 index 00000000..62696c5f --- /dev/null +++ b/sig/datadog/ci/utils/bundle.rbs @@ -0,0 +1,9 @@ +module Datadog + module CI + module Utils + module Bundle + def self.location: () -> String? + end + end + end +end