File search

Summary

We do a depth first search through all directories for files that have names or paths that expect what we're looking for.

We do 2 searches with both being optional:

  • One automated search for default file name patterns
  • One search for user-specified file path patterns

There are 4 arguments you can pass to Codecov to customize the files it uploads.

  • disable_search: Codecov searches for common coverage files by default, that can be skipped by enabling this option. This will not skip the search for user-specified files.
  • search_root: The absolute or relative path to the directory in which to look for files, for both the default search and the user specified search.
  • folders_to_ignore: The names of directories to ignore during both the automated and user-specified file search.
  • files: The paths to files, relative to where codecov is being run from, to look for during the user-specified search.

The search_root and folders_to_ignore are useful for specifying which files to upload in the automated search, and also have the side effect of skipping searching through directories that may have a bunch of files we don't care about, thus improving the speed of looking for files to upload.

Examples

The usage of these options can be best explained using examples, and the files that will be uploaded in those examples.

🚧

Important Note

In these examples, we are going to be ignoring any other arguments you may need to pass to the CLI or Action in order for Codecov to work, like the Token. We will only focus on the arguments that affect file searching.

Let's say we have the following directory structure, where dir is the root of our git repo:

dir/
ā”œā”€ā”€ subdir1/
│   ā”œā”€ā”€ sub_subdir1/
│   │   └── coverage1.xml
│   └── sub_subdir2/
│       └── coverage2.xml
└── subdir2/
    ā”œā”€ā”€ sub_subdir1/
    │   └── coverage3.xml
    └── sub_subdir2/
        └── coverage4.xml

This will upload all the files in this directory:

codecovcli
uses: codecov/codecov-action@v5

This will find no files and fail:

codecovcli --disable-search
uses: codecov/codecov-action@v5
with:
	disable_search: true

This will upload only the files found in subdir1, so coverage1.xml and coverage2.xml

codecovcli --dir subdir1
uses: codecov/codecov-action@v5
with:
	directory: "subdir1"

This will upload coverage2.xml and coverage4.xml since we're starting our search through all directories that don't have the name sub_subdir1

codecovcli --exclude sub_subdir1
uses: codecov/codecov-action@v5
with:
	exclude: "sub_subdir1"

This will upload coverage2.xml since we're starting our search in subdir1 that don't have the name sub_subdir1

codecovcli --dir subdir1 --exclude sub_subdir1
uses: codecov/codecov-action@v5
with:
	directory: "subdir1"
	exclude: "sub_subdir1"

This will upload coverage1.xml since we're starting our search in subdir1 that have the path relative to the directory in which we're running codecov: subdir1/sub_subdir1/coverage1.xml

codecovcli --disable-search --dir subdir1 --file subdir1/sub_subdir1/coverage1.xml 
uses: codecov/codecov-action@v5
with:
	disable_search: true
	directory: "subdir1"
	files: "subdir1/sub_subdir1/coverage1.xml"

This will upload coverage1.xml since we're starting our search in subdir1/sub_subdir1 that have the path relative to the directory in which we're running codecov: subdir1/sub_subdir1/coverage1.xml

codecovcli --disable-search --dir subdir1/sub_subdir1 --file subdir1/sub_subdir1/coverage1.xml 
uses: codecov/codecov-action@v5
with:
	disable_search: true
	directory: "subdir1/sub_subdir1"
	files: "subdir1/sub_subdir1/coverage1.xml"