Skip to content

Commit

Permalink
create coverage.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
sfraczek committed Mar 6, 2024
1 parent 247f885 commit 8832c3a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/building.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
on: [pull_request]

name: Code Coverage

jobs:
coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- 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: Build project
- uses: actions-rs/cargo@v1
with:
command: build
env:
RUSTFLAGS: "-C instrument-coverage"

- name: Run tests for coverage
uses: actions-rs/cargo@v1
with:
command: test
env:
LLVM_PROFILE_FILE: profile-%p-%m.profraw

- name: Generate coverage html report
run: grcov . -s . --binary-path ./target/debug -t html --branch --ignore-not-existing -o ./coverage/

- name: Upload coverage html report
uses: actions/upload-artifact@v2
with:
name: coverage-html-report
path: coverage/


- name: Generate coverage lcov report
run: grcov . -s . --binary-path ./target/debug -t md --branch --ignore-not-existing -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: 90

0 comments on commit 8832c3a

Please sign in to comment.