Skip to content

Commit

Permalink
Add code coverage using codecov.io (open-telemetry#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-Kimberly authored Jun 19, 2020
1 parent c86794e commit 1a54e5d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/.codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
codecov:
require_ci_to_pass: yes
max_report_age: off

coverage:
precision: 2
round: down
range: "80...100"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no

# Relative file path fixing.
# CI file paths must match Git file paths.
# This fix removes the "/home/runner/" prefix
# to coverage report file paths.
fixes:
- "/home/runner/::"
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,19 @@ jobs:
./ci/setup_windows_ci_environment.ps1
- name: run tests
run: ./ci/do_ci.ps1 cmake.test_example_plugin

code_coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: run tests and generate report
run: ./ci/do_ci.sh code.coverage
- name: upload report
uses: codecov/codecov-action@v1
with:
file: /home/runner/build/coverage.info
1 change: 1 addition & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do
* `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer.
* `benchmark`: run all benchmarks.
* `format`: use `tools/format.sh` to enforce text formatting.
* `code.coverage`: build cmake targets and run tests. Then upload coverage report to [codecov.io](https://codecov.io/).

Additionally, `./ci/run_docker.sh` can be invoked with no arguments to get a docker shell where tests
can be run manually.
10 changes: 10 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ elif [[ "$1" == "format" ]]; then
exit 1
fi
exit 0
elif [[ "$1" == "code.coverage" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror --coverage" \
"${SRC_DIR}"
make
make test
lcov --directory $PWD --capture --output-file coverage.info
exit 0
fi

echo "Invalid do_ci.sh target, see ci/README.md for valid targets."
Expand Down
1 change: 1 addition & 0 deletions ci/setup_ci_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ apt-get install --no-install-recommends --no-install-suggests -y \
ca-certificates \
wget \
git
apt-get install -y lcov

0 comments on commit 1a54e5d

Please sign in to comment.