Skip to content

Commit

Permalink
Add CI scripts for GitHub actions.
Browse files Browse the repository at this point in the history
Automate unit testing.
  • Loading branch information
vahancho committed Jul 7, 2023
1 parent 7e841f0 commit b250f7b
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
93 changes: 93 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Test (CMake)

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
branches:
- '*'

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v3

# Install GTest on non Windows nodes
- name: Install GTest
if: matrix.os != 'windows-latest'
working-directory: ${{github.workspace}}
run: |
git clone --branch v1.12.x https://github.com/google/googletest.git
cd googletest
cmake -B build -DBUILD_SHARED_LIBS=ON -DINSTALL_GTEST=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
cmake --build build --config ${{env.BUILD_TYPE}}
sudo cmake --install build --prefix=/usr/local
# Windows only
- name: Install GTest (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
working-directory: ${{github.workspace}}
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
git clone --branch v1.12.x https://github.com/google/googletest.git
cd googletest
cmake -B build -DBUILD_SHARED_LIBS=ON -DINSTALL_GTEST=ON
cmake --build build --config ${{env.BUILD_TYPE}}
cmake --install build --prefix=${{github.workspace}}/googletest/build
- name: Configure CMake
if: matrix.os != 'windows-latest'
working-directory: ${{github.workspace}}
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_TESTING=True

- name: Build
if: matrix.os != 'windows-latest'
# Build your program with the given configuration
run: cmake --build build --config ${{env.BUILD_TYPE}}

# Windows only
- name: Configure CMake (Windows)
if: matrix.os == 'windows-latest'
working-directory: ${{github.workspace}}
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
cmake -B build -DENABLE_TESTING=True -DCMAKE_PREFIX_PATH=${{github.workspace}}\googletest\build
# Windows only
- name: Build (Windows)
if: matrix.os == 'windows-latest'
shell: cmd
# Build your program with the given configuration
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
cmake --build build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
run: ctest -C ${{env.BUILD_TYPE}} --verbose

# Uploade coverage report only for Linux
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
verbose: true
gcov: true
gcov_include: ${{github.workspace}}/src/graphene.h
16 changes: 15 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,18 @@ add_custom_command(
$<TARGET_FILE_DIR:${TARGET}>
)

add_test(NAME unittests COMMAND unittest)
# Coverage support.
option(CODE_COVERAGE "Enable coverage reporting" ON)
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(${TARGET} PUBLIC
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(${TARGET} PUBLIC --coverage)
else()
target_link_libraries(${TARGET} PUBLIC --coverage)
endif()
endif()

0 comments on commit b250f7b

Please sign in to comment.