Skip to content

Commit 2506a90

Browse files
committed
Add Codecov coverage workflow with modern Rust coverage tooling
- Add .github/workflows/coverage.yml with grcov and -Cinstrument-coverage - Uses nightly Rust with llvm-tools-preview for accurate coverage - Integrates with Codecov for badge display via shields.io
1 parent fc98d86 commit 2506a90

5 files changed

Lines changed: 92 additions & 5 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
coverage:
14+
name: Generate test coverage
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Install system dependencies
19+
run: sudo apt-get update && sudo apt-get install -y libfontconfig1-dev pkg-config
20+
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Install Rust nightly with required components
25+
uses: dtolnay/rust-toolchain@nightly
26+
with:
27+
components: llvm-tools-preview
28+
29+
- name: Cache cargo registry and target directory
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
~/.cargo/registry
34+
~/.cargo/git
35+
target
36+
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
37+
restore-keys: |
38+
${{ runner.os }}-cargo-coverage-
39+
${{ runner.os }}-cargo-
40+
41+
- name: Install grcov
42+
uses: taiki-e/install-action@v2
43+
with:
44+
tool: grcov
45+
46+
- name: Build
47+
run: cargo build --verbose
48+
env:
49+
RUSTFLAGS: '-Cinstrument-coverage'
50+
RUSTDOCFLAGS: '-Cinstrument-coverage'
51+
52+
- name: Run tests
53+
run: cargo test --all-features --verbose
54+
env:
55+
CARGO_INCREMENTAL: '0'
56+
RUSTFLAGS: '-Cinstrument-coverage'
57+
RUSTDOCFLAGS: '-Cinstrument-coverage'
58+
LLVM_PROFILE_FILE: 'cargo-test-%p-%m.profraw'
59+
60+
- name: Generate coverage report
61+
run: |
62+
grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" --ignore '*/tests/*' -o coverage.lcov
63+
64+
- name: Upload coverage to Codecov
65+
uses: codecov/codecov-action@v4
66+
with:
67+
files: coverage.lcov
68+
fail_ci_if_error: true
69+
flags: unittests
70+
verbose: true

.github/workflows/rust.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ on:
99
jobs:
1010
build-and-test:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
rust: [stable, '1.89.0', nightly]
16+
include:
17+
- rust: nightly
18+
allow-failure: true
19+
continue-on-error: ${{ matrix.allow-failure || false }}
1220

1321
steps:
1422
- name: Install system dependencies
@@ -17,10 +25,11 @@ jobs:
1725
- name: Checkout code
1826
uses: actions/checkout@v4
1927

20-
- name: Set up Rust
21-
uses: actions-rs/toolchain@v1
28+
- name: Set up Rust ${{ matrix.rust }}
29+
uses: dtolnay/rust-toolchain@master
2230
with:
23-
toolchain: '1.89.0'
31+
toolchain: ${{ matrix.rust }}
32+
components: rustfmt, clippy
2433

2534
- name: Build
2635
run: cargo build --verbose

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Cargo.lock
2121
# Jujutsu VCS files
2222
.jj/
2323

24+
# Git files
25+
.git/
26+
2427
# OS generated files
2528
.DS_Store
2629
Thumbs.db

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
[![crates.io Latest Release](https://img.shields.io/crates/v/rslife.svg)](https://crates.io/crates/rslife)
1010
[![Documentation](https://docs.rs/rslife/badge.svg)](https://docs.rs/rslife/latest/rslife/)
11+
[![codecov](https://img.shields.io/codecov/c/github/hnlearndev/rslife?logo=codecov&label=coverage)](https://app.codecov.io/gh/hnlearndev/rslife)
12+
[![codspeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/nautechsystems/nautilus_trader)
13+
1114
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE-MIT)
1215
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](./LICENSE-APACHE)
1316

@@ -65,7 +68,7 @@ Or add this to your `Cargo.toml`:
6568

6669
```toml
6770
[dependencies]
68-
rslife = "0.2.7"
71+
rslife = "0.2.9"
6972
```
7073

7174
The crate is designed with three main layers to make actuarial computations convenient (more on [architecture from Wiki](https://github.com/hnlearndev/rslife/wiki/Architecture)), as illustrated below:
@@ -327,14 +330,15 @@ See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT.md](LICENSE-MIT.md) for de
327330

328331
**Willian Nguyen** - [hieunt(dot)hello(at)gmail(dot)com](mailto:)
329332

330-
**Project Link** - [https://github.com/hnlearndev/rslife](https://github.com/hnlearndev/rslife)
333+
**Project link** - [https://github.com/hnlearndev/rslife](https://github.com/hnlearndev/rslife)
331334

332335
## References
333336

334337
- [Actuarial Mathematics for Life Contingent Risks](https://www.goodreads.com/book/show/58306503-actuarial-mathematics-for-life-contingent-risks)
335338
- [Actuarial Mathematics](https://www.goodreads.com/book/show/1715653.Actuarial_Mathematics)
336339
- [Society of Actuaries Mortality and Morbidity Tables](https://mort.soa.org)
337340
- [Institute and Faculty of Actuaries Mortality and Morbidity Tables](https://www.actuaries.org.uk/learn-and-develop/continuous-mortality-investigation/cmi-mortality-and-morbidity-tables)
341+
- [Australian Government Actuary](https://aga.gov.au)
338342
- Standard actuarial notation and practices
339343

340344
## Similar Projects

src/mt_config/ifoa_xls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl IFOAMortXLS {
126126
let structure = info_from_id.0;
127127
let url_suffix = info_from_id.1;
128128

129+
// TODO: url now also get from ONS not just IFOA
129130
let url = format!("https://www.actuaries.org.uk/documents/{url_suffix}");
130131

131132
let id = match structure {

0 commit comments

Comments
 (0)