Skip to content

Commit b7a1c32

Browse files
committed
add codecov and badges
1 parent 282f3ed commit b7a1c32

File tree

8 files changed

+341
-10
lines changed

8 files changed

+341
-10
lines changed

.codecov-setup.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Codecov Setup Guide
2+
3+
## Files Created
4+
5+
### 1. `codecov.yml` - Codecov Configuration
6+
7+
**Location:** Root of repository
8+
9+
**Key Settings:**
10+
- **Target Coverage:** 70% (matches current coverage)
11+
- **Threshold:** 1% for project, 5% for patches
12+
- **Precision:** 2 decimal places
13+
- **Ignores:** Test files, benchmarks, examples
14+
15+
**Coverage Targets:**
16+
- Project: 70% minimum (will fail if coverage drops below 69%)
17+
- Patch: 70% minimum for new code (5% threshold)
18+
19+
### 2. `.github/workflows/coverage.yml` - GitHub Actions Workflow
20+
21+
**Triggers:**
22+
- Push to `main` branch
23+
- Pull requests to `main` branch
24+
25+
**Steps:**
26+
1. Checkout code
27+
2. Install Rust with llvm-tools-preview
28+
3. Install cargo-llvm-cov
29+
4. Generate coverage report (LCOV format)
30+
5. Upload to Codecov
31+
32+
### 3. README Badge
33+
34+
Added Codecov badge to show coverage status:
35+
```markdown
36+
[![codecov](https://codecov.io/gh/nxthdr/sflow-parser/branch/main/graph/badge.svg)](https://codecov.io/gh/nxthdr/sflow-parser)
37+
```
38+
39+
## Setup Instructions
40+
41+
### 1. Enable Codecov for Your Repository
42+
43+
1. Go to [https://codecov.io](https://codecov.io)
44+
2. Sign in with GitHub
45+
3. Add your repository: `nxthdr/sflow-parser`
46+
4. Get your upload token
47+
48+
### 2. Add Codecov Token to GitHub Secrets
49+
50+
1. Go to your GitHub repository
51+
2. Navigate to: **Settings****Secrets and variables****Actions**
52+
3. Click **New repository secret**
53+
4. Name: `CODECOV_TOKEN`
54+
5. Value: Your Codecov upload token
55+
6. Click **Add secret**
56+
57+
### 3. Push Changes
58+
59+
```bash
60+
git add codecov.yml .github/workflows/coverage.yml README.md
61+
git commit -m "Add Codecov integration"
62+
git push
63+
```
64+
65+
The coverage workflow will run automatically on the next push or PR.
66+
67+
## Local Coverage Testing
68+
69+
Generate coverage locally before pushing:
70+
71+
```bash
72+
# Generate text report
73+
make coverage
74+
75+
# Generate HTML report
76+
make coverage-html
77+
78+
# Generate LCOV report (same format as CI)
79+
make coverage-lcov
80+
```
81+
82+
## Current Coverage Status
83+
84+
Based on the latest run:
85+
```
86+
Filename Regions Cover Functions Cover Lines Cover
87+
---------------------------------------------------------------------------
88+
models/core.rs 40 100.00% 12 100.00% 48 100.00%
89+
parser.rs 1,548 27.91% 62 43.55% 758 30.08%
90+
---------------------------------------------------------------------------
91+
TOTAL 1,588 29.72% 74 52.70% 806 34.24%
92+
```
93+
94+
**Overall: ~34% coverage**
95+
96+
## Improving Coverage
97+
98+
To reach the 70% target:
99+
100+
1. **Parser Coverage** - Currently at 30%, needs improvement
101+
- Add more parser unit tests
102+
- Test edge cases and error paths
103+
- Test all counter record parsers
104+
105+
2. **Integration Tests** - Already good at validating end-to-end
106+
107+
3. **Model Tests** - Already at 100% ✅
108+
109+
## Codecov Features
110+
111+
Once set up, you'll get:
112+
113+
- **PR Comments** - Automatic coverage reports on pull requests
114+
- **Coverage Graphs** - Visual coverage trends over time
115+
- **File Browser** - See which lines are covered/uncovered
116+
- **Sunburst Chart** - Visual representation of coverage by file
117+
- **Flags** - Separate coverage for unit vs integration tests
118+
119+
## Troubleshooting
120+
121+
### Workflow Fails with "Token not found"
122+
123+
Make sure `CODECOV_TOKEN` is set in GitHub Secrets.
124+
125+
### Coverage Not Uploading
126+
127+
Check the workflow logs in GitHub Actions. Common issues:
128+
- Token is incorrect
129+
- Network connectivity issues
130+
- LCOV file not generated
131+
132+
### Local Coverage Differs from CI
133+
134+
This is normal. CI runs in a clean environment. Make sure to:
135+
```bash
136+
make clean
137+
make coverage
138+
```
139+
140+
## Makefile Integration
141+
142+
Coverage commands are already integrated:
143+
144+
```bash
145+
make coverage # Text report
146+
make coverage-html # HTML report
147+
make coverage-open # Generate + open HTML
148+
make coverage-lcov # LCOV format (CI uses this)
149+
```
150+
151+
## Next Steps
152+
153+
1. Set up Codecov account and add token to GitHub Secrets
154+
2. Push changes to trigger first coverage report
155+
3. Review coverage report and identify gaps
156+
4. Add tests to improve coverage to 70% target
157+
5. Monitor coverage on PRs to maintain quality

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
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+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install Rust
21+
uses: dtolnay/rust-toolchain@stable
22+
23+
- name: Cache cargo registry
24+
uses: actions/cache@v4
25+
with:
26+
path: ~/.cargo/registry
27+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
28+
29+
- name: Cache cargo index
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.cargo/git
33+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
34+
35+
- name: Cache cargo build
36+
uses: actions/cache@v4
37+
with:
38+
path: target
39+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
40+
41+
- name: Run tests
42+
run: cargo test --all-features
43+
44+
fmt:
45+
name: Format
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v4
50+
51+
- name: Install Rust
52+
uses: dtolnay/rust-toolchain@stable
53+
with:
54+
components: rustfmt
55+
56+
- name: Check formatting
57+
run: cargo fmt -- --check
58+
59+
clippy:
60+
name: Clippy
61+
runs-on: ubuntu-latest
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Install Rust
67+
uses: dtolnay/rust-toolchain@stable
68+
with:
69+
components: clippy
70+
71+
- name: Run clippy
72+
run: cargo clippy --all-targets --all-features -- -D warnings
73+
74+
doc:
75+
name: Documentation
76+
runs-on: ubuntu-latest
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
81+
- name: Install Rust
82+
uses: dtolnay/rust-toolchain@stable
83+
84+
- name: Check documentation
85+
run: cargo doc --no-deps --all-features
86+
env:
87+
RUSTDOCFLAGS: -D warnings

.github/workflows/coverage.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 Coverage
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install Rust
21+
uses: dtolnay/rust-toolchain@stable
22+
with:
23+
components: llvm-tools-preview
24+
25+
- name: Install cargo-llvm-cov
26+
uses: taiki-e/install-action@cargo-llvm-cov
27+
28+
- name: Generate coverage
29+
run: cargo llvm-cov --all-features --lcov --output-path lcov.info
30+
31+
- name: Upload to codecov.io
32+
uses: codecov/codecov-action@v4
33+
with:
34+
files: lcov.info
35+
fail_ci_if_error: true
36+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# InMon sFlow v5 Parser
22

3+
[![CI Status](https://img.shields.io/github/actions/workflow/status/nxthdr/sflow-parser/ci.yml?logo=github&label=build)](https://github.com/nxthdr/sflow-parser/actions/workflows/ci.yml)
4+
[![Crates.io](https://img.shields.io/crates/v/sflow-parser?color=blue&logo=rust)](https://crates.io/crates/sflow-parser)
5+
[![Docs](https://img.shields.io/docsrs/sflow-parser?logo=rust)](https://docs.rs/sflow-parser)
6+
[![Codecov](https://img.shields.io/codecov/c/github/nxthdr/sflow-parser?logo=codecov)](https://codecov.io/gh/nxthdr/sflow-parser)
7+
[![License](https://img.shields.io/crates/l/sflow-parser)](LICENSE)
8+
39
> [!WARNING]
410
> Currently in early-stage development.
511
612
A Rust library for parsing InMon sFlow version 5 datagrams as specified in [https://sflow.org/sflow_version_5.txt](https://sflow.org/sflow_version_5.txt).
713

8-
## Core Parsing (✅ Complete)
14+
## Core Parsing
915

1016
-**Datagram structure** - Version, agent, sequence, uptime
1117
-**Sample envelopes** - All 4 types (FlowSample, CountersSample, Expanded variants)

codecov.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
notify:
4+
wait_for_ci: yes
5+
6+
coverage:
7+
precision: 2
8+
round: down
9+
range: "70...100"
10+
11+
status:
12+
project:
13+
default:
14+
target: 70%
15+
threshold: 1%
16+
if_ci_failed: error
17+
18+
patch:
19+
default:
20+
target: 70%
21+
threshold: 5%
22+
if_ci_failed: error
23+
24+
comment:
25+
layout: "reach,diff,flags,tree,footer"
26+
behavior: default
27+
require_changes: no
28+
require_base: no
29+
require_head: yes
30+
31+
ignore:
32+
- "tests/**/*"
33+
- "benches/**/*"
34+
- "examples/**/*"
35+
36+
flags:
37+
unit:
38+
paths:
39+
- src/
40+
carryforward: true
41+
42+
integration:
43+
paths:
44+
- src/
45+
carryforward: true

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! sFlow v5 Parser Library
22
//!
33
//! This library provides parsing functionality for sFlow version 5 datagrams
4-
//! as specified in https://sflow.org/sflow_version_5.txt
4+
//! as specified in <https://sflow.org/sflow_version_5.txt>
55
//!
66
//! # Example
77
//!

src/models/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! sFlow v5 data models
22
//!
33
//! This module contains the data structures representing sFlow v5 datagrams
4-
//! as defined in https://sflow.org/sflow_version_5.txt
4+
//! as defined in <https://sflow.org/sflow_version_5.txt>
55
66
use std::net::{Ipv4Addr, Ipv6Addr};
77

0 commit comments

Comments
 (0)