Skip to content

Commit 153e6ac

Browse files
authored
Add code coverage to CI with Coveralls integration (payjoin#385)
This brings the github actions up-to-date with latest versions and adds more descriptive names to the workflow steps. It also swaps the ordering of `rust-cache` and the rust toolchain installation steps so that cache actually works. Finally, a new CI step adds code coverage measurements using `cargo-llvm` and uploads the results to Coveralls.
2 parents ce46c67 + 6554d2a commit 153e6ac

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

.github/workflows/rust.yml

+41-23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
name: Test and Build
1+
name: Continuous integration
22

33
on: [push, pull_request]
44

55
jobs:
6-
7-
test:
6+
Test:
87
runs-on: ubuntu-latest
98
strategy:
109
fail-fast: false
@@ -13,43 +12,62 @@ jobs:
1312
- 1.63.0 # MSRV
1413
- stable
1514
- nightly
16-
1715
steps:
18-
- uses: actions/checkout@v2
19-
- uses: Swatinem/rust-cache@v1.2.0
20-
- uses: actions-rs/toolchain@v1
16+
- name: "Checkout repo"
17+
uses: actions/checkout@v4
18+
- name: "Install ${{ matrix.rust }} toolchain"
19+
# https://github.com/dtolnay/rust-toolchain?tab=readme-ov-file#inputs
20+
uses: dtolnay/rust-toolchain@master
2121
with:
2222
toolchain: ${{ matrix.rust }}
23-
override: true
23+
- name: "Use cache"
24+
uses: Swatinem/rust-cache@v2
2425
- name: Run tests
2526
run: RUST_LOG=debug bash contrib/test.sh
2627

27-
rustfmt:
28+
Format:
2829
runs-on: ubuntu-latest
2930
steps:
30-
- uses: actions/checkout@v2
31-
- uses: Swatinem/rust-cache@v1.2.0
32-
- uses: actions-rs/toolchain@v1
33-
with:
34-
toolchain: nightly
35-
override: true
31+
- name: "Checkout repo"
32+
uses: actions/checkout@v4
33+
- name: "Install nightly toolchain"
34+
uses: dtolnay/rust-toolchain@nightly
35+
- name: "Use cache"
36+
uses: Swatinem/rust-cache@v2
3637
- run: rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu
37-
- name: fmt check
38+
- name: "Run formatting check"
3839
run: cargo fmt --all -- --check
3940

40-
clippy:
41+
Lint:
4142
runs-on: ubuntu-latest
4243
steps:
4344
- name: "Checkout repo"
4445
uses: actions/checkout@v4
45-
- name: "Use caching"
46-
uses: Swatinem/rust-cache@v1.2.0
4746
- name: "Install nightly toolchain"
48-
uses: actions-rs/toolchain@v1
49-
with:
50-
toolchain: nightly
51-
override: true
47+
uses: dtolnay/rust-toolchain@nightly
48+
- name: "Use cache"
49+
uses: Swatinem/rust-cache@v2
5250
- name: "Install clippy"
5351
run: rustup component add clippy --toolchain nightly-x86_64-unknown-linux-gnu
5452
- name: "Run linting"
5553
run: bash contrib/lint.sh
54+
55+
Coverage:
56+
name: Code coverage
57+
runs-on: ubuntu-latest
58+
strategy:
59+
fail-fast: false
60+
steps:
61+
- name: "Checkout repo"
62+
uses: actions/checkout@v4
63+
- name: "Install toolchain"
64+
# https://github.com/dtolnay/rust-toolchain
65+
uses: dtolnay/rust-toolchain@stable
66+
- name: "Use cache"
67+
uses: Swatinem/rust-cache@v2
68+
- name: "Install cargo-llvm-cov"
69+
uses: taiki-e/install-action@cargo-llvm-cov
70+
- name: "Generate code coverage for tests"
71+
run: bash contrib/coverage.sh
72+
- name: "Upload report to coveralls"
73+
uses: coverallsapp/github-action@v2

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Seeking review of the code that verifies there is no overpayment. Contributions
7272
- [x] CI
7373
- [x] Integration tests
7474
- [ ] Fuzzing
75-
- [ ] Coverage measurement
75+
- [x] Coverage measurement
7676

7777
## Minimum Supported Rust Version (MSRV)
7878

contrib/coverage.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions
5+
cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results
6+
cargo llvm-cov --no-report --features=send,receive
7+
cargo llvm-cov --no-report --features=v2,danger-local-https,io
8+
cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests

0 commit comments

Comments
 (0)