Skip to content

Commit

Permalink
chore(ci): Add Rust Unit Test code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vifino committed Feb 8, 2024
1 parent 8cdd2fc commit 659af66
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,34 @@ env:
jobs:
build:
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -C instrument-coverage
LLVM_PROFILE_FILE: /tmp/nvmetcfg-%p-%8m.profraw

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview

- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

- name: Merge profile data and export LCOV
run: |
PATH="$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin:$PATH"
llvm-cov --version
llvm-profdata merge --sparse -o /tmp/nvmetcfg.profdata /tmp/nvmetcfg-*.profraw
llvm-cov export -format=lcov -instr-profile=/tmp/nvmetcfg.profdata \
--ignore-filename-regex='/.cargo/registry' \
--show-instantiation-summary \
$(cargo test --tests --no-run --message-format=json | jq -r "select(.profile.test == true) | .filenames[]" | xargs -I {} printf "-object {} ") > nvmetcfg.lcov
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: nvmetcfg.lcov
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
default = nvmetcfg;
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [rust-bin.stable.latest.default cargo-bloat];
buildInputs = with pkgs; [
(rust-bin.stable.latest.default.override {
extensions = [ "llvm-tools-preview" ];
})
cargo-bloat
cargo-llvm-cov
];
};

checks = {
Expand Down

0 comments on commit 659af66

Please sign in to comment.