|
| 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 | +[](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 |
0 commit comments