From 34f21003334f9bcb033eabb59c72758e5c16c6dd Mon Sep 17 00:00:00 2001 From: Sylwester Fraczek Date: Thu, 7 Mar 2024 09:29:54 +0100 Subject: [PATCH] create coverage.yaml (#102) * create coverage.yaml * fix * fixup * add installing dependencies * speedup by removing build step and fix md->markdown * remove empty line * set coverage threshold to 65 --- .github/workflows/building.yaml | 2 +- .github/workflows/coverage.yaml | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/building.yaml b/.github/workflows/building.yaml index e197659..750a71e 100644 --- a/.github/workflows/building.yaml +++ b/.github/workflows/building.yaml @@ -14,7 +14,7 @@ jobs: profile: minimal toolchain: stable override: true - - run: rustup component add rustfmt + components: rustfmt - uses: actions-rs/cargo@v1 with: command: fmt diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000..dc913d5 --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,61 @@ +name: Code Coverage + +on: [pull_request] + +jobs: + coverage: + runs-on: ubuntu-latest + + steps: + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: llvm-tools-preview + + - name: Install grcov + uses: actions-rs/cargo@v1 + with: + command: install + args: grcov + + - name: Run tests for coverage + uses: actions-rs/cargo@v1 + with: + command: test + env: + LLVM_PROFILE_FILE: profile-%p-%m.profraw + RUSTFLAGS: "-C instrument-coverage" + + - name: Generate coverage html report + run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing --ignore "/*" -o ./coverage/ + + - name: Upload coverage html report + uses: actions/upload-artifact@v4 + with: + name: coverage-html-report + path: coverage/ + + - name: Generate coverage lcov report + run: grcov . -s . --binary-path ./target/debug -t markdown --branch --ignore-not-existing --ignore "/*" -o coverage.md + + - name: Check coverage percentage + run: | + COVERAGE_PERCENTAGE=$(tail -n 1 coverage.md | grep -oP '(\d+(\.\d+)?)(?=%)') + echo "Coverage percentage is $COVERAGE_PERCENTAGE%" + if (( $(echo "$COVERAGE_PERCENTAGE < $COVERAGE_THRESHOLD" | bc -l) )); then + echo "Code coverage is below $COVERAGE_THRESHOLD%. Failing the workflow." + exit 1 + fi + env: + COVERAGE_THRESHOLD: 65