Skip to content

Commit

Permalink
updated ci with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
benja263 committed Jul 22, 2024
1 parent ba594db commit 642aba3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 46 deletions.
68 changes: 22 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:

strategy:
matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
python-version: ['3.10']

Expand All @@ -27,68 +26,45 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
- name: Install dependencies on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
brew update
brew install libomp llvm
brew install cmake
echo "LLVM_DIR=$(brew --prefix)/opt/llvm" >> $GITHUB_ENV
echo "BREW_PREFIX=$(brew --prefix)" >> $GITHUB_ENV
echo "LDFLAGS=-L$(brew --prefix libomp)/lib -L$(brew --prefix llvm)/lib -L$(brew --prefix llvm)/lib/c++ -Wl,-rpath,$(brew --prefix llvm)/lib/c++" >> $GITHUB_ENV
echo "CPPFLAGS=-I$(brew --prefix libomp)/include -I$(brew --prefix llvm)/include" >> $GITHUB_ENV
echo "OpenMP_C_FLAGS=-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" >> $GITHUB_ENV
echo "OpenMP_CXX_FLAGS=-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" >> $GITHUB_ENV
echo "OpenMP_C_LIB_NAMES=omp" >> $GITHUB_ENV
echo "OpenMP_CXX_LIB_NAMES=omp" >> $GITHUB_ENV
echo "OpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib" >> $GITHUB_ENV
sudo apt-get update
sudo apt-get install -y lcov g++ gcc
- name: Install dependencies and build
- name: Set environment variable for coverage
run: echo "COVERAGE=1" >> $GITHUB_ENV

- name: Install Python dependencies and build the project with coverage
run: |
python -m pip install --upgrade pip
python -m pip install coverage
pip install .
- name: Build the project
run: |
python setup.py build
- name: Run tests
run: |
python -m unittest discover tests
coverage run --source=gbrl -m unittest discover tests
- name: Generate coverage report
run: |
pip install coverage
coverage run --source=my_module -m unittest discover tests
coverage report
coverage xml
- name: Generate C++/CUDA coverage report
run: |
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --list coverage.info
lcov --add-tracefile coverage.info --output-file combined.info
coverage combine
coverage xml -o combined_coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./coverage.xml
files: |
./coverage.info
./combined_coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true

coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install coverage
pip install cpp-coveralls
- name: Run C++/CUDA coverage
run: |
coveralls --exclude-pattern 'tests/*' --gcov-options '\-lp' --root . --build-root build/
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
#-- Options
include(CMakeDependentOption)
option(USE_CUDA "Build with GPU acceleration" OFF)

if(DEFINED ENV{COVERAGE} AND $ENV{COVERAGE} STREQUAL "1")
message(STATUS "Coverage build")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif()

# Check for CUDA availability
if (USE_CUDA AND NOT APPLE)
find_package(CUDAToolkit QUIET HINTS $ENV{CONDA_PREFIX})
Expand Down

0 comments on commit 642aba3

Please sign in to comment.