Skip to content

Commit 159a585

Browse files
vmxraulkgalarghanorth
authored
Add code coverage report (#120)
Generate a code coverage report and add it as artifact as well as uploading it to CodeCov. Co-authored-by: raulk <[email protected]> Co-authored-by: Piotr Galar <[email protected]> Co-authored-by: Alex <[email protected]>
1 parent 63c5033 commit 159a585

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,63 @@ jobs:
5959
BUILD_FIL_NETWORK: ${{ matrix.network }}
6060
run: |
6161
cargo run --locked -- -o output/builtin-actors.car
62+
coverage:
63+
runs-on: ubuntu-latest
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
CARGO_INCREMENTAL: 0
67+
CACHE_SKIP_SAVE: ${{ matrix.push == '' || matrix.push == 'false' }}
68+
steps:
69+
- name: Checking out
70+
uses: actions/checkout@v2
71+
- name: Install Rust toolchain
72+
uses: ./.github/actions/rust-cargo-run
73+
with:
74+
command: version
75+
components: llvm-tools-preview
76+
github_token: ${{ secrets.GITHUB_TOKEN }}
77+
- name: Put LLVM tools into the PATH
78+
run: echo "${HOME}/.rustup/toolchains/$(cat rust-toolchain)-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin" >> $GITHUB_PATH
79+
- name: Install demangler
80+
run: cargo install rustfilt
81+
- name: Create coverage report
82+
env:
83+
# Incremental build is not supported when profiling.
84+
CARGO_INCREMENTAL: 0
85+
# Make sure that each run of an executable creates a new profile file,
86+
# with the default name they would override each other.
87+
LLVM_PROFILE_FILE: "%m.profraw"
88+
# -Cinstrument-coverage: enable llvm coverage instrumentation
89+
# -Ccodegen-units=1: building in parallel is not supported when profiling
90+
# -Copt-level=0: disable optimizations for more accurate coverage
91+
# -Coverflow-checks=off: checking for overflow is not needed for coverage reporting
92+
# -Cinline-threshold=0: do not inline
93+
# For code coverage the `-Clink-dead-code` flag should be set, as dead
94+
# code should be considered as not covered code. Though this would make
95+
# the build fail, hence it is not set.
96+
RUSTFLAGS: -Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off -Cinline-threshold=0
97+
run: cargo test --workspace --exclude fil_builtin_actors_bundle
98+
- name: Merge profiling data
99+
# Do *not* use sparse output. It leads to more lines that are not taken
100+
# into account at all
101+
run: llvm-profdata merge --output=default.profdata $(find . -name '*.profraw')
102+
- name: Create HTML coverage report
103+
# The compiled files contain the coverage information. From running the
104+
# tests we don't know what those files are called, hence use all files
105+
# from the `./target/debug/deps` directory which don't have an extension.
106+
run: |
107+
OBJECT_OPTIONS=($(find ./target/debug/deps/* -name '*' -not -name '*\.*' -printf ' --object %p'))
108+
# Create HTML report of this project, we don't care about coverage of
109+
# dependencies
110+
llvm-cov show --Xdemangler=rustfilt --show-expansions --show-line-counts-or-regions --ignore-filename-regex=".cargo|.rustup|/rustc|./tests/" --format=html --output-dir=./llvm-show --instr-profile=default.profdata ${OBJECT_OPTIONS[@]}
111+
# Create file to be uploaded to codecov
112+
llvm-cov export --ignore-filename-regex=".cargo|.rustup|/rustc|./tests" --format=lcov --instr-profile=default.profdata ${OBJECT_OPTIONS[@]} > lcov.info
113+
- name: Archive code coverage results
114+
uses: actions/upload-artifact@v3
115+
with:
116+
name: code-coverage-report
117+
path: llvm-show/*
118+
- name: Upload coverage to Codecov
119+
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
120+
with:
121+
files: lcov.info

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.63.0
1+
1.63.0

0 commit comments

Comments
 (0)