Skip to content

Commit ab17348

Browse files
authored
chore: add codecov coverage tracking (#493)
Inspired by #492 but integrated into the existing workflows.
1 parent 0882855 commit ab17348

5 files changed

Lines changed: 122 additions & 2 deletions

File tree

.codecov.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
show_carryforward_flags: true
18+
19+
flag_management:
20+
default_rules:
21+
carryforward: true
22+
23+
flags:
24+
dashcore:
25+
paths: [dash/src/]
26+
dashcore_hashes:
27+
paths: [hashes/src/]
28+
dashcore-private:
29+
paths: [internals/src/]
30+
dash-network:
31+
paths: [dash-network/src/]
32+
dash-spv:
33+
paths: [dash-spv/src/]
34+
key-wallet:
35+
paths: [key-wallet/src/]
36+
key-wallet-manager:
37+
paths: [key-wallet-manager/src/]
38+
dash-network-ffi:
39+
paths: [dash-network-ffi/src/]
40+
dash-spv-ffi:
41+
paths: [dash-spv-ffi/src/]
42+
key-wallet-ffi:
43+
paths: [key-wallet-ffi/src/]
44+
dashcore-rpc:
45+
paths: [rpc-client/src/]
46+
dashcore-rpc-json:
47+
paths: [rpc-json/src/]
48+
49+
ignore:
50+
- "**/tests/**"
51+
- "**/tests.rs"
52+
- "**/test_utils/**"
53+
- "**/test_utils.rs"
54+
- "**/examples/**"
55+
- "fuzz/**"
56+
- "contrib/**"

.github/scripts/ci_config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ 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))
176180

177181
for crate in crates:
178182
# Skip dash-fuzz on Windows
@@ -182,7 +186,10 @@ def run_group_tests(args):
182186

183187
github_group_start(f"Testing {crate}")
184188

185-
cmd = ["cargo", "test", "-p", crate, "--all-features"]
189+
if coverage:
190+
cmd = ["cargo", "llvm-cov", "--no-report", "-p", crate, "--all-features"]
191+
else:
192+
cmd = ["cargo", "test", "-p", crate, "--all-features"]
186193
result = subprocess.run(cmd)
187194

188195
github_group_end()
@@ -225,6 +232,11 @@ def main():
225232
run_group_parser = subparsers.add_parser("run-group", help="Run tests for a group")
226233
run_group_parser.add_argument("group", help="Group name")
227234
run_group_parser.add_argument("--os", default="ubuntu-latest", help="OS name")
235+
run_group_parser.add_argument(
236+
"--coverage",
237+
action="store_true",
238+
help="Use cargo-llvm-cov for coverage collection",
239+
)
228240

229241
args = parser.parse_args()
230242

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

Lines changed: 29 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,33 @@ 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 }}
62+
fail_ci_if_error: true

.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/dashpay/rust-dashcore/branch/master"><img alt="Coverage (master)" src="https://codecov.io/gh/dashpay/rust-dashcore/branch/master/graph/badge.svg"/></a>
15+
<a href="https://codecov.io/gh/dashpay/rust-dashcore/branch/v0.42-dev"><img alt="Coverage (develop)" src="https://codecov.io/gh/dashpay/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/dashpay/rust-dashcore/graph/badge.svg?flag=dashcore)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dashcore) |
28+
| dashcore_hashes | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dashcore_hashes)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dashcore_hashes) |
29+
| dashcore-private | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dashcore-private)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dashcore-private) |
30+
| dash-network | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dash-network)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dash-network) |
31+
| dash-spv | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dash-spv)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dash-spv) |
32+
| key-wallet | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=key-wallet)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=key-wallet) |
33+
| key-wallet-manager | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=key-wallet-manager)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=key-wallet-manager) |
34+
| dash-network-ffi | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dash-network-ffi)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dash-network-ffi) |
35+
| dash-spv-ffi | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dash-spv-ffi)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dash-spv-ffi) |
36+
| key-wallet-ffi | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=key-wallet-ffi)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=key-wallet-ffi) |
37+
| dashcore-rpc | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dashcore-rpc)](https://codecov.io/gh/dashpay/rust-dashcore?flags[0]=dashcore-rpc) |
38+
| dashcore-rpc-json | [![codecov](https://codecov.io/gh/dashpay/rust-dashcore/graph/badge.svg?flag=dashcore-rpc-json)](https://codecov.io/gh/dashpay/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)