CI Build and Test #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI Build and Test | |
on: | |
push: | |
branches: | |
- main # Run on push to the main branch | |
pull_request: | |
branches: | |
- main # Run on pull requests to the main branch | |
workflow_dispatch: | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the repository | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
# Step 2: Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install Python Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r test_requirements.txt | |
- name: Run Python Tests with Coverage | |
run: | | |
pytest --maxfail=5 --disable-warnings --cov=. --cov-report=xml | |
- name: Upload Python Coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: python | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
# Step 3: Install C++ build tools | |
- name: Install C++ Build Tools | |
run: sudo apt-get update && sudo apt-get install -y build-essential cmake g++ lcov | |
# Step 4: Configure and Build C++ Project | |
- name: Configure and Build C++ Project | |
run: | | |
mkdir -p build | |
cd build | |
cmake -DCMAKE_CXX_FLAGS="--coverage" .. # Enable coverage flags | |
make | |
# Step 5: Run C++ Tests | |
- name: Run C++ Tests | |
run: | | |
cd build | |
./NNet # Replace `NNet` with your executable name | |
# Step 6: Generate C++ Coverage Report | |
- name: Generate C++ Coverage Report | |
run: | | |
cd build | |
lcov --capture --directory . --output-file coverage.info | |
lcov --list coverage.info | |
# Step 7: Upload C++ Coverage to Codecov | |
- name: Upload C++ Coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
flags: cpp | |
files: build/coverage.info # Path to the coverage report | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |