Skip to content

Commit 9f39c71

Browse files
committed
chore: add codecov coverage tracking
Inspired by #492 but integrated into the existing workflows.
1 parent 2c8e81f commit 9f39c71

5 files changed

Lines changed: 119 additions & 2 deletions

File tree

.codecov.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 2%
7+
patch:
8+
default:
9+
target: auto
10+
threshold: 2%
11+
12+
13+
comment:
14+
layout: "diff, flags, files"
15+
behavior: default
16+
require_changes: true
17+
18+
flags:
19+
dashcore:
20+
paths: [dash/src/]
21+
dashcore_hashes:
22+
paths: [hashes/src/]
23+
dashcore-private:
24+
paths: [internals/src/]
25+
dash-network:
26+
paths: [dash-network/src/]
27+
dash-spv:
28+
paths: [dash-spv/src/]
29+
key-wallet:
30+
paths: [key-wallet/src/]
31+
key-wallet-manager:
32+
paths: [key-wallet-manager/src/]
33+
dash-network-ffi:
34+
paths: [dash-network-ffi/src/]
35+
dash-spv-ffi:
36+
paths: [dash-spv-ffi/src/]
37+
key-wallet-ffi:
38+
paths: [key-wallet-ffi/src/]
39+
dashcore-rpc:
40+
paths: [rpc-client/src/]
41+
dashcore-rpc-json:
42+
paths: [rpc-json/src/]
43+
44+
ignore:
45+
- "**/tests/**"
46+
- "**/test_utils/**"
47+
- "**/examples/**"
48+
- "fuzz/**"
49+
- "contrib/**"

.github/scripts/ci_config.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ def run_group_tests(args):
173173

174174
crates = groups[args.group] or []
175175
failed = []
176+
coverage = getattr(args, "coverage", False)
177+
178+
if coverage:
179+
github_output("crate_flags", ",".join(crates))
180+
181+
if coverage:
182+
github_group_start("Cleaning coverage state")
183+
subprocess.run(["cargo", "llvm-cov", "clean", "--workspace"])
184+
github_group_end()
176185

177186
for crate in crates:
178187
# Skip dash-fuzz on Windows
@@ -182,7 +191,10 @@ def run_group_tests(args):
182191

183192
github_group_start(f"Testing {crate}")
184193

185-
cmd = ["cargo", "test", "-p", crate, "--all-features"]
194+
if coverage:
195+
cmd = ["cargo", "llvm-cov", "--no-report", "-p", crate, "--all-features"]
196+
else:
197+
cmd = ["cargo", "test", "-p", crate, "--all-features"]
186198
result = subprocess.run(cmd)
187199

188200
github_group_end()
@@ -225,6 +237,11 @@ def main():
225237
run_group_parser = subparsers.add_parser("run-group", help="Run tests for a group")
226238
run_group_parser.add_argument("group", help="Group name")
227239
run_group_parser.add_argument("--os", default="ubuntu-latest", help="OS name")
240+
run_group_parser.add_argument(
241+
"--coverage",
242+
action="store_true",
243+
help="Use cargo-llvm-cov for coverage collection",
244+
)
228245

229246
args = parser.parse_args()
230247

.github/workflows/build-and-test.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
groups:
1010
required: true
1111
type: string
12+
coverage:
13+
required: false
14+
type: boolean
15+
default: false
1216

1317
permissions:
1418
contents: read
@@ -26,9 +30,32 @@ jobs:
2630
steps:
2731
- uses: actions/checkout@v6
2832
- uses: dtolnay/rust-toolchain@stable
33+
with:
34+
components: ${{ inputs.coverage && 'llvm-tools' || '' }}
2935
- uses: Swatinem/rust-cache@v2
3036
with:
3137
shared-key: "test-${{ inputs.os }}-${{ matrix.group }}"
38+
39+
- name: Install cargo-llvm-cov
40+
if: inputs.coverage
41+
uses: taiki-e/install-action@cargo-llvm-cov
42+
3243
- run: pip install pyyaml
3344
- name: Run tests
34-
run: python .github/scripts/ci_config.py run-group ${{ matrix.group }} --os ${{ inputs.os }}
45+
id: tests
46+
run: >
47+
python .github/scripts/ci_config.py run-group ${{ matrix.group }}
48+
--os ${{ inputs.os }}
49+
${{ inputs.coverage && '--coverage' || '' }}
50+
51+
- name: Generate coverage report
52+
if: inputs.coverage
53+
run: cargo llvm-cov report --lcov --output-path lcov.info
54+
55+
- name: Upload coverage to Codecov
56+
if: inputs.coverage
57+
uses: codecov/codecov-action@v5
58+
with:
59+
files: lcov.info
60+
flags: ${{ steps.tests.outputs.crate_flags }}
61+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ jobs:
6464
with:
6565
os: ubuntu-latest
6666
groups: ${{ needs.verify-execution.outputs.groups }}
67+
coverage: true
68+
secrets: inherit
6769

6870
test-ubuntu-arm:
6971
name: Ubuntu ARM

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@
1111
<a href="https://crates.io/crates/dash"><img alt="Crate Info" src="https://img.shields.io/crates/v/dash.svg"/></a>
1212
<a href="https://github.com/dashevo/rust-dashcore/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
1313
<a href="https://github.com/dashevo/rust-dashcore/actions?query=workflow%3AContinuous%20integration"><img alt="CI Status" src="https://github.com/dashevo/rust-dashcore/workflows/Continuous%20integration/badge.svg"></a>
14+
<a href="https://codecov.io/gh/dashevo/rust-dashcore/branch/master"><img alt="Coverage (master)" src="https://codecov.io/gh/dashevo/rust-dashcore/branch/master/graph/badge.svg"/></a>
15+
<a href="https://codecov.io/gh/dashevo/rust-dashcore/branch/v0.42-dev"><img alt="Coverage (develop)" src="https://codecov.io/gh/dashevo/rust-dashcore/branch/v0.42-dev/graph/badge.svg"/></a>
1416
<a href="https://docs.rs"><img alt="API Docs" src="https://img.shields.io/badge/docs.rs-rust--dashcore-green"/></a>
1517
<a href="#minimum-supported-rust-version-msrv"><img alt="Rustc Version 1.89+" src="https://img.shields.io/badge/rustc-1.89%2B-lightgrey.svg"/></a>
1618
<img alt="Lines of code" src="https://img.shields.io/tokei/lines/github/dashevo/rust-dashcore">
1719
</p>
1820
</div>
1921

22+
<details>
23+
<summary>Per-crate coverage</summary>
24+
25+
| Crate | Coverage |
26+
|-------|----------|
27+
| dashcore | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dashcore)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dashcore) |
28+
| dashcore_hashes | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dashcore_hashes)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dashcore_hashes) |
29+
| dashcore-private | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dashcore-private)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dashcore-private) |
30+
| dash-network | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dash-network)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dash-network) |
31+
| dash-spv | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dash-spv)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dash-spv) |
32+
| key-wallet | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=key-wallet)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=key-wallet) |
33+
| key-wallet-manager | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=key-wallet-manager)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=key-wallet-manager) |
34+
| dash-network-ffi | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dash-network-ffi)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dash-network-ffi) |
35+
| dash-spv-ffi | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dash-spv-ffi)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dash-spv-ffi) |
36+
| key-wallet-ffi | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=key-wallet-ffi)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=key-wallet-ffi) |
37+
| dashcore-rpc | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dashcore-rpc)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dashcore-rpc) |
38+
| dashcore-rpc-json | [![codecov](https://codecov.io/gh/dashevo/rust-dashcore/graph/badge.svg?flag=dashcore-rpc-json)](https://codecov.io/gh/dashevo/rust-dashcore?flags[0]=dashcore-rpc-json) |
39+
40+
</details>
41+
2042
For contributors: see CONTRIBUTING.md and AGENTS.md for branch policy and commands.
2143

2244
[Documentation](https://dashcore.readme.io/docs)

0 commit comments

Comments
 (0)