From 98452c4f1c91c50c30db0491a85f953e605aaaa5 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:16:10 +0530 Subject: [PATCH] ci: add code coverage workflow with llvm-cov (#246) # Rationale for this change Coverage reports help a lot with code quality and review. # What changes are included in this PR? * Added llvm-cov workflow. # Are these changes tested? Yes. --------- Co-authored-by: Jay White --- .github/workflows/lint-and-test.yml | 35 +++++++++++++++++++++++++++++ CONTRIBUTING.md | 8 ++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 3cb23d904..d3a21d6ce 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -136,6 +136,41 @@ jobs: - name: Run clippy::pedantic for proof-of-sql-parser run: cargo clippy --lib -p proof-of-sql-parser -- -D clippy::pedantic + coverage: + name: Code Coverage + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y clang lld + - uses: taiki-e/install-action@cargo-llvm-cov + - name: Clean Previous Coverage Artifacts + run: cargo llvm-cov clean --workspace + - name: Run Tests to Generate Coverage Data (All Features) + run: cargo llvm-cov --no-report --all-features + #- name: Run Tests to Generate Coverage Data (Rayon Only) + # run: cargo llvm-cov --no-report --no-default-features --features="rayon" + #- name: Run Tests to Generate Coverage Data (Blitzar Only) + # run: cargo llvm-cov --no-report --no-default-features --features="blitzar" + #- name: Run Tests to Generate Coverage Data (std only) + # run: cargo llvm-cov --no-report --no-default-features --features="std" + - name: Generate Final LCOV Report (Merged Coverage) + run: cargo llvm-cov report --summary-only --fail-under-lines 90 + # Future CodeCov Integration + # To integrate with CodeCov in the future,, follow these steps: + # 1. Add the CodeCov token to the repository secrets. + # 2. Use the CodeCov Action to upload the coverage report. For more detailed info refer to [CodeCov Documentation](https://docs.codecov.com/docs). + # + # - name: Generate Final LCOV Report (Merged Coverage) + # run: cargo llvm-cov report --lcov --output-path lcov.info --fail-under-lines 95 + # - name: Upload Coverage to Codecov + # uses: codecov/codecov-action@v2 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # files: lcov.info + # fail_ci_if_error: true + # Run cargo fmt --all -- --config imports_granularity=Crate,group_imports=One --check format: name: Format diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8e80a76e6..add16e0da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,7 @@ The following guideline is heavily based on the [Angular Project Guideline](http - [Submitting a Pull Request (PR)](#submit-pr) - [Addressing review feedback](#address-review) - [Updating the commit message](#updating-commit-message) + - [Running Code Coverage Locally](#coverage-locally) - [After your pull request is merged](#after-pr-merged) - [Coding Rules](#rules) - [Commit Message Guidelines](#commit-guidelines) @@ -246,6 +247,12 @@ In order to update the commit message of the last commit on your branch: NOTE: If you need to update the commit message of an earlier commit, you can use `git rebase` in interactive mode. See the [git docs](https://git-scm.com/docs/git-rebase#_interactive_mode) for more details. +### Running Code Coverage Locally +To run code coverage locally, install `cargo-llvm-cov` by following the instructions here: [cargo-llvm-cov Installation](https://github.com/taiki-e/cargo-llvm-cov). + +For users of VSCode, you can display coverage reports directly in the IDE by following these instructions: [Display Coverage in VSCode](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#display-coverage-in-vs-code). + +You can exclude specific functions from coverage by adding an attribute to your code: [Exclude Functions from Coverage](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#exclude-function-from-coverage). ### After your pull request is merged @@ -275,7 +282,6 @@ After your pull request is merged, you can safely delete your branch and pull th git pull --ff upstream main ``` - ## Coding Rules To ensure consistency throughout the source code, keep these rules in mind as you are working: