Skip to content

Commit

Permalink
Measure test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Maksym Pavlenko <[email protected]>
  • Loading branch information
mxpv committed Sep 15, 2023
1 parent 9388ecf commit bef92da
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- run: cargo build --all-features --timings
- uses: actions/upload-artifact@v3
with:
name: cargo-timing
name: timings
path: target/cargo-timings/cargo-timing.html
if-no-files-found: error

Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/cover.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Coverage
on:
pull_request_target:

jobs:
coverage:
name: Collect
runs-on: ubuntu-latest
timeout-minutes: 15

permissions:
statuses: write

steps:
- uses: actions/checkout@v4

- run: |
sudo apt-get install protobuf-compiler
- name: Install grcov
run: |
cargo install grcov
grcov --version
- name: Tests
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw"
run: |
sudo -E $(command -v cargo) test --all-features
# Fix permissions after sudo.
sudo chown -R $(whoami) target/coverage/
- name: Collect coverage data
run: |
grcov . \
--source-dir . \
--binary-path ./target/debug/ \
--branch --ignore-not-existing \
--output-types html,markdown \
--keep-only 'crates/*' \
--output-path ./target/coverage/
- uses: actions/upload-artifact@v3
with:
name: coverage
path: target/coverage/html/
if-no-files-found: error

- name: Publish job summary
run: |
echo "# Coverage" >> $GITHUB_STEP_SUMMARY
cat target/coverage/markdown.md >> $GITHUB_STEP_SUMMARY
- run: echo "coverage=$(cat target/coverage/markdown.md | grep 'Total coverage')" >> $GITHUB_OUTPUT
id: coverage

- name: Create commit status
uses: actions/github-script@v6
if: success()
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
description: '${{ steps.coverage.outputs.coverage }}',
})
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.71"
components = ["rustfmt", "clippy"]
components = ["rustfmt", "clippy", "llvm-tools-preview"]

0 comments on commit bef92da

Please sign in to comment.