|
59 | 59 | BUILD_FIL_NETWORK: ${{ matrix.network }}
|
60 | 60 | run: |
|
61 | 61 | 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 |
0 commit comments