Add code coverage and testing CI stuff
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
coverage:
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
target: 80%
|
||||||
|
threshold: 5%
|
||||||
|
patch:
|
||||||
|
default:
|
||||||
|
target: 80%
|
||||||
|
threshold: 5%
|
||||||
|
|
||||||
|
comment:
|
||||||
|
layout: "reach,diff,flags,tree"
|
||||||
|
behavior: default
|
||||||
|
require_changes: false
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
- "test_*.cpp"
|
||||||
|
- "builddir/**/*"
|
||||||
|
- "**/*.hpp" # Header files typically don't need coverage
|
||||||
|
|
||||||
|
flags:
|
||||||
|
unittests:
|
||||||
|
paths:
|
||||||
|
- handler.cpp
|
||||||
|
- main.cpp
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
# GitHub Actions CI/CD Setup
|
||||||
|
|
||||||
|
This repository includes a comprehensive GitHub Actions workflow for C++20 compilation, testing, and code coverage reporting.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
### 🔧 Multi-Platform Build & Test
|
||||||
|
- **Ubuntu Latest**: Primary development target with GCC
|
||||||
|
- **macOS Latest**: Cross-platform compatibility with Clang
|
||||||
|
- **Windows Latest**: Broader compatibility with GCC via vcpkg
|
||||||
|
|
||||||
|
### 🧪 Comprehensive Testing
|
||||||
|
- Runs all Google Test unit tests
|
||||||
|
- Validates security features (directory traversal protection)
|
||||||
|
- Fails build on any test failures
|
||||||
|
- Uploads test logs as artifacts
|
||||||
|
|
||||||
|
### 📊 Code Coverage Reporting
|
||||||
|
- **Coverage Tool**: gcov + lcov for detailed coverage analysis
|
||||||
|
- **Integration**: Automatic upload to Codecov.io
|
||||||
|
- **Reports**: HTML coverage reports as downloadable artifacts
|
||||||
|
- **Thresholds**: Configurable coverage targets (default: 80%)
|
||||||
|
- **PR Comments**: Automatic coverage change reporting
|
||||||
|
|
||||||
|
## Workflow Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
CI Workflow
|
||||||
|
├── Build & Test Matrix (Ubuntu, macOS, Windows)
|
||||||
|
│ ├── Install Dependencies (Boost, Google Test)
|
||||||
|
│ ├── Meson Setup & Configure
|
||||||
|
│ ├── Compile with C++20
|
||||||
|
│ ├── Run Unit Tests
|
||||||
|
│ └── Upload Test Artifacts
|
||||||
|
└── Coverage Analysis (Ubuntu only)
|
||||||
|
├── Build with Coverage Flags
|
||||||
|
├── Run Tests with Coverage Collection
|
||||||
|
├── Generate lcov Reports
|
||||||
|
├── Upload to Codecov
|
||||||
|
└── Generate HTML Reports
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setup Instructions
|
||||||
|
|
||||||
|
### 1. Repository Setup
|
||||||
|
1. Push this repository to GitHub
|
||||||
|
2. Update the badge URLs in `README.md`:
|
||||||
|
```markdown
|
||||||
|
[](https://github.com/YOUR_USERNAME/YOUR_REPO_NAME/actions)
|
||||||
|
[](https://codecov.io/gh/YOUR_USERNAME/YOUR_REPO_NAME)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Codecov Integration
|
||||||
|
1. Visit [codecov.io](https://codecov.io) and sign in with GitHub
|
||||||
|
2. Add your repository to Codecov
|
||||||
|
3. No additional setup required - the workflow handles token-free uploads
|
||||||
|
|
||||||
|
### 3. Branch Protection (Optional)
|
||||||
|
Configure branch protection rules in GitHub:
|
||||||
|
- Require status checks to pass before merging
|
||||||
|
- Require branches to be up to date before merging
|
||||||
|
- Include the "Build and Test" and "Code Coverage" checks
|
||||||
|
|
||||||
|
## Configuration Files
|
||||||
|
|
||||||
|
### `.github/workflows/ci.yml`
|
||||||
|
Main CI/CD workflow with:
|
||||||
|
- Multi-platform build matrix
|
||||||
|
- Dependency management for each OS
|
||||||
|
- Test execution and artifact collection
|
||||||
|
- Coverage analysis and reporting
|
||||||
|
|
||||||
|
### `.codecov.yml`
|
||||||
|
Codecov configuration with:
|
||||||
|
- Coverage targets (80% project, 80% patch)
|
||||||
|
- File exclusions (test files, build directories)
|
||||||
|
- PR comment formatting
|
||||||
|
- Coverage flags for different components
|
||||||
|
|
||||||
|
### `.gitignore` Updates
|
||||||
|
Added coverage-related file exclusions:
|
||||||
|
- `*.gcda`, `*.gcno`, `*.gcov` - Coverage data files
|
||||||
|
- `coverage/` - Coverage report directories
|
||||||
|
- `coverage*.info` - lcov report files
|
||||||
|
|
||||||
|
## Workflow Triggers
|
||||||
|
|
||||||
|
The CI workflow runs on:
|
||||||
|
- **Push** to `main` and `develop` branches
|
||||||
|
- **Pull Requests** targeting `main` and `develop` branches
|
||||||
|
|
||||||
|
## Artifacts Generated
|
||||||
|
|
||||||
|
### Test Results
|
||||||
|
- Test logs from all platforms
|
||||||
|
- Available for 90 days after workflow completion
|
||||||
|
|
||||||
|
### Coverage Reports
|
||||||
|
- HTML coverage reports (viewable in browser)
|
||||||
|
- lcov data files for further analysis
|
||||||
|
- Codecov integration for web-based viewing
|
||||||
|
|
||||||
|
## Coverage Analysis
|
||||||
|
|
||||||
|
The coverage analysis focuses on:
|
||||||
|
- `handler.cpp` - Core business logic
|
||||||
|
- Security validation functions
|
||||||
|
- File I/O operations
|
||||||
|
- Excludes test files and system headers
|
||||||
|
|
||||||
|
### Coverage Thresholds
|
||||||
|
- **Project Coverage**: 80% minimum
|
||||||
|
- **Patch Coverage**: 80% minimum for new code
|
||||||
|
- **Threshold**: 5% tolerance for coverage changes
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Common Issues
|
||||||
|
|
||||||
|
1. **Dependency Installation Failures**
|
||||||
|
- Check if package names are correct for the target OS
|
||||||
|
- Verify vcpkg installation on Windows
|
||||||
|
|
||||||
|
2. **Coverage Upload Failures**
|
||||||
|
- Coverage uploads are set to non-blocking (`fail_ci_if_error: false`)
|
||||||
|
- Check Codecov repository configuration
|
||||||
|
|
||||||
|
3. **Test Failures**
|
||||||
|
- Review test logs in the workflow artifacts
|
||||||
|
- Ensure all tests pass locally before pushing
|
||||||
|
|
||||||
|
### Local Testing
|
||||||
|
|
||||||
|
Test the workflow components locally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Standard build and test
|
||||||
|
meson setup builddir
|
||||||
|
meson compile -C builddir
|
||||||
|
meson test -C builddir --verbose
|
||||||
|
|
||||||
|
# Coverage build and test
|
||||||
|
meson setup builddir-coverage -Db_coverage=true
|
||||||
|
meson compile -C builddir-coverage
|
||||||
|
meson test -C builddir-coverage
|
||||||
|
```
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
### Adding New Platforms
|
||||||
|
Extend the build matrix in `.github/workflows/ci.yml`:
|
||||||
|
```yaml
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-20.04]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changing Coverage Targets
|
||||||
|
Modify `.codecov.yml`:
|
||||||
|
```yaml
|
||||||
|
coverage:
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
target: 90% # Increase to 90%
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding Static Analysis
|
||||||
|
Add steps to the workflow for tools like:
|
||||||
|
- cppcheck
|
||||||
|
- clang-tidy
|
||||||
|
- AddressSanitizer/UBSan (already partially enabled)
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
The workflow includes security best practices:
|
||||||
|
- Pinned action versions (`@v4`, `@v3`)
|
||||||
|
- No secrets required for basic functionality
|
||||||
|
- Minimal permissions for workflow execution
|
||||||
|
- Static linking to reduce runtime dependencies
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, develop ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, develop ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
name: Build and Test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
include:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
cc: gcc
|
||||||
|
cxx: g++
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Meson and Ninja
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install meson ninja
|
||||||
|
|
||||||
|
- name: Install dependencies (Ubuntu)
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libboost-system-dev libgtest-dev build-essential
|
||||||
|
|
||||||
|
- name: Setup build directory
|
||||||
|
run: |
|
||||||
|
meson setup builddir
|
||||||
|
env:
|
||||||
|
CC: ${{ matrix.cc }}
|
||||||
|
CXX: ${{ matrix.cxx }}
|
||||||
|
|
||||||
|
- name: Compile
|
||||||
|
run: |
|
||||||
|
meson compile -C builddir
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
meson test -C builddir --verbose
|
||||||
|
|
||||||
|
- name: Upload test results
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: test-results-${{ matrix.os }}
|
||||||
|
path: builddir/meson-logs/
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
name: Code Coverage
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build-and-test
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install Meson and Ninja
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install meson ninja
|
||||||
|
|
||||||
|
- name: Install dependencies and coverage tools
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libboost-system-dev libgtest-dev build-essential lcov
|
||||||
|
|
||||||
|
- name: Setup build directory with coverage
|
||||||
|
run: |
|
||||||
|
meson setup builddir -Db_coverage=true
|
||||||
|
env:
|
||||||
|
CC: gcc
|
||||||
|
CXX: g++
|
||||||
|
|
||||||
|
- name: Compile with coverage
|
||||||
|
run: |
|
||||||
|
meson compile -C builddir
|
||||||
|
|
||||||
|
- name: Run tests with coverage
|
||||||
|
run: |
|
||||||
|
meson test -C builddir --verbose
|
||||||
|
|
||||||
|
- name: Generate coverage report
|
||||||
|
run: |
|
||||||
|
# Create coverage directory
|
||||||
|
mkdir -p coverage
|
||||||
|
|
||||||
|
# Capture coverage data
|
||||||
|
lcov --capture --directory builddir --output-file coverage/coverage.info
|
||||||
|
|
||||||
|
# Remove system headers and test files from coverage
|
||||||
|
lcov --remove coverage/coverage.info '/usr/*' '*/test_*' '*/gtest/*' --output-file coverage/coverage_filtered.info
|
||||||
|
|
||||||
|
# Generate HTML report
|
||||||
|
genhtml coverage/coverage_filtered.info --output-directory coverage/html
|
||||||
|
|
||||||
|
# Display coverage summary
|
||||||
|
lcov --summary coverage/coverage_filtered.info
|
||||||
|
|
||||||
|
- name: Upload coverage reports to Codecov
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
file: coverage/coverage_filtered.info
|
||||||
|
flags: unittests
|
||||||
|
name: codecov-umbrella
|
||||||
|
fail_ci_if_error: false
|
||||||
|
|
||||||
|
- name: Upload coverage HTML report
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: coverage-report
|
||||||
|
path: coverage/html/
|
||||||
|
|
||||||
|
- name: Coverage Summary
|
||||||
|
run: |
|
||||||
|
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "Coverage data has been uploaded to Codecov and HTML report is available as an artifact." >> $GITHUB_STEP_SUMMARY
|
||||||
|
lcov --summary coverage/coverage_filtered.info >> $GITHUB_STEP_SUMMARY
|
||||||
@@ -24,6 +24,14 @@ test_handler
|
|||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
|
||||||
|
# Coverage files
|
||||||
|
*.gcda
|
||||||
|
*.gcno
|
||||||
|
*.gcov
|
||||||
|
coverage/
|
||||||
|
coverage.info
|
||||||
|
coverage_filtered.info
|
||||||
|
|
||||||
# OS generated files
|
# OS generated files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.DS_Store?
|
.DS_Store?
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
# finger
|
# finger
|
||||||
|
|
||||||
|
[](https://github.com/waffle2k/finger/actions)
|
||||||
|
[](https://codecov.io/gh/waffle2k/finger)
|
||||||
|
|
||||||
A silly finger service written in c++20
|
A silly finger service written in c++20
|
||||||
|
|
||||||
# Compiling:
|
# Compiling:
|
||||||
|
|||||||
Reference in New Issue
Block a user