Added coverage and clang-tidy jobs #176
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
# NOTE: This workflow is in the test_cpp_cache repository with full comments | |
name: Continuous Integration | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
- 'feature/*' | |
- 'bugfix/*' | |
- 'release/*' | |
- 'hotfix/*' | |
paths-ignore: | |
- 'docs/**' | |
- 'LICENSE' | |
- 'LICENSE.txt' | |
- 'README.md' | |
pull_request: | |
branches: | |
- main | |
- develop | |
paths-ignore: | |
- 'docs/**' | |
- 'LICENSE' | |
- 'LICENSE.txt' | |
- 'README.md' | |
env: | |
BUILD_TYPE: Release | |
SCCACHE_GHA_ENABLED: "true" | |
CACHE_VCPKG_LIBRARIES: "fmt catch2" | |
jobs: | |
test: | |
name: ${{ matrix.config.os }} ${{ matrix.config.compiler }} | |
runs-on: ${{ matrix.config.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
# Reference: https://github.com/actions/runner-images | |
- { os: "ubuntu-24.04", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "/usr/bin/g++-14", cmake_cxx_launcher: "ccache" } | |
- { os: "ubuntu-24.04", compiler: "llvm", cmake_gen: Ninja Multi-Config, cmake_cxx: "/usr/lib/llvm-18/bin/clang++", cmake_cxx_launcher: "ccache" } | |
# project won't compile using g++ on macos-15; can use macos-14 instead | |
#- { os: "macos-15", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++-14", cmake_cxx_launcher: "ccache" } | |
- { os: "macos-14", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++-14", cmake_cxx_launcher: "ccache" } | |
- { os: "macos-15", compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "$(brew --prefix llvm@18)/bin/clang++", cmake_cxx_launcher: "ccache" } | |
- { os: windows-2022, compiler: "msvc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "cl", cmake_cxx_launcher: "sccache" } | |
- { os: windows-2022, compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "clang++", cmake_cxx_launcher: "sccache" } | |
- { os: windows-2022, compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++", cmake_cxx_launcher: "sccache" } | |
#- { os: "macos-14", compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "clang++", cmake_cxx_launcher: "ccache" } | |
steps: | |
- uses: actions/checkout@v4 | |
# Reference: https://github.com/hendrikmuhs/ccache-action | |
- name: Cache (non-Windows) | |
if: runner.os != 'Windows' | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ runner.os }}-${{ matrix.config.compiler }}-${{ env.BUILD_TYPE }} | |
# Reference: https://github.com/Mozilla-Actions/sccache-action | |
- name: Cache (Windows) | |
if: runner.os == 'Windows' | |
uses: mozilla-actions/[email protected] | |
# Reference: https://github.com/aminya/setup-cpp | |
- name: Install C++ Tools | |
uses: aminya/setup-cpp@v1 | |
with: | |
vcvarsall: ${{ runner.os == 'Windows' && matrix.config.compiler == 'msvc' }} | |
ninja: true | |
# Reference: https://cmake.org/cmake/help/latest/manual/cmake.1.html | |
- name: Configure CMake | |
run: cmake -B ./build -G "${{matrix.config.cmake_gen}}" -DCMAKE_CXX_COMPILER="${{matrix.config.cmake_cxx}}" -DCMAKE_CXX_COMPILER_LAUNCHER="${{matrix.config.cmake_cxx_launcher}}" | |
- name: Build | |
run: cmake --build ./build --config ${{env.BUILD_TYPE}} | |
# Reference: https://cmake.org/cmake/help/latest/manual/ctest.1.html | |
- name: Test | |
working-directory: ./build | |
run: ctest -C ${{env.BUILD_TYPE}} | |
vcpkg: | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Generate hash for libraries | |
id: generate-hash | |
run: | | |
HASH=$(echo -n "${{ env.CACHE_VCPKG_LIBRARIES }}" | sha256sum | cut -d' ' -f1) | |
echo "CACHE_VCPKG_LIBRARIES_HASH=${HASH}" >> $GITHUB_ENV | |
- name: vcpkg cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/vcpkg | |
key: | |
${{ runner.os }}-vcpkg-${{ env.CACHE_VCPKG_LIBRARIES_HASH }} | |
# Reference: https://github.com/aminya/setup-cpp | |
- name: Install vcpkg | |
uses: aminya/setup-cpp@v1 | |
with: | |
vcpkg: true | |
- name: Install vcpkg dependencies | |
run: vcpkg install ${{ env.CACHE_VCPKG_LIBRARIES }} | |
#run: vcpkg install fmt catch2 | |
# # Taken from doctest github | |
coverage: | |
needs: vcpkg | |
runs-on: ubuntu-24.04 | |
env: | |
BUILD_TYPE: Debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: vcpkg cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/vcpkg | |
key: ${{ runner.os }}-vcpkg-${{ env.CACHE_VCPKG_LIBRARIES_HASH }} | |
- name: Install C++ Tools | |
run: sudo apt-get install -y ninja-build lcov | |
- name: Configure CMake | |
run: cmake -B ./build -G "Ninja Multi-Config" -D CMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake | |
- name: Build | |
run: cmake --build ./build --config ${{ env.BUILD_TYPE }} | |
- name: Test | |
run: ctest --test-dir ./build --no-tests=error | |
- name: LCOV | |
run: | | |
mkdir coverage | |
lcov -c -d ./build/ -o coverage/lcov.info --include "*include/caff*" | |
- name: Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: ./coverage/lcov.info | |
fail_ci_if_error: true | |
# Taken from doctest github | |
clang-tidy: | |
needs: vcpkg | |
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository | |
runs-on: ubuntu-24.04 | |
env: | |
BUILD_TYPE: Debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: vcpkg cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/vcpkg | |
key: ${{ runner.os }}-vcpkg-${{ env.CACHE_VCPKG_LIBRARIES_HASH }} | |
- name: Install Ninja | |
run: sudo apt-get install -y ninja-build | |
# -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake | |
# -warnings-as-errors=* | |
# ;-header-filter=include/caff/.* | |
- name: Configure CMake | |
run: cmake -B ./build -S . -G "Ninja Multi-Config" -D CMAKE_CXX_COMPILER=/usr/lib/llvm-18/bin/clang++ -D CMAKE_EXPORT_COMPILE_COMMANDS=ON -D CMAKE_CXX_CLANG_TIDY="clang-tidy-18;-header-filter=include/caff/.*" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake | |
- name: Build | |
run: cmake --build ./build --config ${{ env.BUILD_TYPE }} | |