Testing with Docker

Worthwhile to mention that the docker run command should also set the "CI" environment variable to "true". On the CI service, e.g. GitHub Actions, it is set, but if you don't explicitly set it in the docker run call it won't be set and then Codecov won't detect GitHub Actions, at least not in Ruby (see https://github.com/codecov/codecov-ruby/blob/484767f1c3d7992a9d7fedd6dc72d35a80d04f70/lib/codecov.rb#L68-L69)

Running tests inside a Docker container is a popular technique, and with one small extra step Codecov will integrate seamlessly. Because of the containerization, reports generated in the container are not retrievable outside of it, but we have two techniques to help Codecov collect reports.

Codecov Inside Docker

The easiest and most popular technique is to pass environment variables through the container.

# request codecov to detect CI environment to pass through to docker
ci_env=`bash <(curl -s https://codecov.io/env)`
docker run $ci_env -e CI=true ...
   |----- inside docker container
   | # exec tests
   | # Your Codecov CLI approach here
   | # See more at https://docs.codecov.com/docs/codecov-uploader
   | ./codecov

Codecov Outside Docker

Pass coverage reports out of the container through a mounted directory, and then run Codecov. This requires you to know the report files and where to put them.

# create a shared folder to store reports in
mkdir shared
# include shared folder when running docker
# make sure you move your reports into the shared folder while in docker
docker run -v "$PWD/shared:/shared" ...
   |----- inside docker container
   | # run test
   | mv coverage.txt shared
# now run codecov in project directory to discover reports in shared folder

# Your Codecov CLI approach here
# See more at https://docs.codecov.com/docs/codecov-uploader
./codecov