Skip to content

Commit

Permalink
add settings option to ignore code coverage for certain paths
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed May 8, 2024
1 parent 8d3ce5c commit 16b04ed
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative "../ext/settings"
require_relative "../utils/bundle"

module Datadog
module CI
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lib/datadog/ci/ext/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/ci/ext/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
20 changes: 20 additions & 0 deletions lib/datadog/ci/utils/bundle.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions sig/datadog/ci/ext/environment.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/ci/ext/settings.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions sig/datadog/ci/utils/bundle.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Datadog
module CI
module Utils
module Bundle
def self.location: () -> String?
end
end
end
end

0 comments on commit 16b04ed

Please sign in to comment.