Skip to content

Commit

Permalink
Initial build, test and coverage workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp authored Apr 23, 2024
1 parent 99a5553 commit 79441bb
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 10 deletions.
189 changes: 189 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: build & test
on:
push:
branches: [master, development]
pull_request:
branches: [master, development]

jobs:
build:
name: |
${{ matrix.config.prefix }}
${{ matrix.config.compiler_name }}-${{ matrix.config.compiler_version }}
${{ matrix.config.suffix }}
(C++${{ matrix.cxx_standard }}, ${{ matrix.build_mode }})
runs-on: ${{ matrix.config.os }}
container: ${{ matrix.config.container }}

strategy:
fail-fast: false
matrix:
build_mode: [Debug, Release]
cxx_standard: [20, 23]
config:
#clang-18
- {
prefix: "Linux",
suffix: "/libc++",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/clang:18" },
compiler_name: "clang",
compiler_version: 18,
libcxx: true,
asan: true
}
- {
prefix: "Linux",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/clang:18" },
compiler_name: "clang",
compiler_version: 18,
libcxx: false,
asan: true
}
#clang-17
- {
prefix: "Linux",
suffix: "/libc++",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/clang:17" },
compiler_name: "clang",
compiler_version: 17,
libcxx: true,
asan: true
}
- {
prefix: "Linux",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/clang:17" },
compiler_name: "clang",
compiler_version: 17,
libcxx: false,
asan: true
}
#gcc-14
- {
prefix: "Linux",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/gcc:14" },
compiler_name: "gcc",
compiler_version: 14,
libcxx: false,
asan: true
}
#gcc-13
- {
prefix: "Linux",
os: ubuntu-latest,
container: { image: "ghcr.io/dnkpp/gcc:13" },
compiler_name: "gcc",
compiler_version: 13,
libcxx: false,
asan: true
}
# msvc v143
- {
prefix: "Windows 2022",
os: windows-2022,
compiler_name: "msvc",
compiler_version: v143,
cmake_generator: Visual Studio 17 2022,
libcxx: false,
asan: false
}
# msvc ClangCl
- {
prefix: "Windows 2022",
os: windows-2022,
compiler_name: "msvc",
compiler_version: ClangCl,
cmake_generator: Visual Studio 17 2022,
libcxx: false,
asan: false
}
# AppleClang
- {
prefix: "macOS",
os: macos-latest,
compiler_name: "AppleClang",
compiler_version: "17.0.6",
compiler_url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-arm64-apple-darwin22.0.tar.xz",
package_name: "clang+llvm-17.0.6-arm64-apple-darwin22.0",
asan: true
}

steps:
- uses: actions/checkout@v4

- name: Setup macOS
if: startsWith(matrix.config.os, 'macos')
shell: bash
run: |
env brew install ninja
# download into current directory and follow http redirects (-L)
curl -sS -L -o clang.tar.xz ${{ matrix.config.compiler_url }}
# extract into subdirectory
tar -xf clang.tar.xz -C ..
CLANG_PATH=$PWD/../${{ matrix.config.package_name }}/bin
echo "CC=$(echo $CLANG_PATH/clang)" >> $GITHUB_ENV
echo "CXX=$(echo $CLANG_PATH/clang++)" >> $GITHUB_ENV
echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DCMAKE_BUILD_TYPE=${{ matrix.build_mode }})" >> $GITHUB_ENV
- name: Clang libc++ setup
if: ${{ matrix.config.compiler_name == 'clang' && matrix.config.libcxx == true }}
shell: bash
run: |
echo "CXX_FLAGS=$(echo $CXX_FLAGS -stdlib=libc++)" >> $GITHUB_ENV
echo "LINK_FLAGS=$(echo $LINK_FLAGS -lc++abi)" >> $GITHUB_ENV
- name: Setup linux
if: ${{ matrix.config.prefix == 'Linux' }}
shell: bash
run: |
echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DCMAKE_BUILD_TYPE=${{ matrix.build_mode }})" >> $GITHUB_ENV
- name: Setup msvc
if: ${{ matrix.config.compiler_name == 'msvc' }}
shell: bash
run: |
echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -G\"${{ matrix.config.cmake_generator }}\" -T\"${{ matrix.config.compiler_version }}\" -Ax64)" >> $GITHUB_ENV
echo "CMAKE_BUILD_EXTRA=$(echo $CMAKE_BUILD_EXTRA --config ${{ matrix.build_mode }})" >> $GITHUB_ENV
- name: Enable Address and Undefined Sanitizer
if: ${{ matrix.config.asan == true }}
shell: bash
run: |
echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DSANITIZE_ADDRESS=YES -DSANITIZE_UNDEFINED=YES)" >> $GITHUB_ENV
# ASan has some serious trouble with libc++ exception mechanism
# see: https://github.com/llvm/llvm-project/issues/59432
- name: Disable alloc_dealloc_mismatch detection with libc++
if: ${{ matrix.config.asan == true && matrix.config.libcxx == true}}
shell: bash
run: |
echo "ASAN_OPTIONS=$(echo $ASAN_OPTIONS:alloc_dealloc_mismatch=0)" >> $GITHUB_ENV
- name: Configure
shell: bash
run: |
cmake \
-S . \
-B build \
-D CMAKE_VERBOSE_MAKEFILE=yes \
-D CMAKE_CXX_FLAGS:STRING="${{ env.CXX_FLAGS }}" \
-D CMAKE_EXE_LINKER_FLAGS:STRING="${{ env.LINK_FLAGS }}" \
-D MIMICPP_FORCED_CXX_STANDARD="${{ matrix.cxx_standard }}" \
${{ env.CMAKE_CONFIG_EXTRA }}
- name: Build
shell: bash
run: |
cmake --build build \
-j4 \
${{ env.CMAKE_BUILD_EXTRA }}
- name: Run tests
shell: bash
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --test-dir build/test -C ${{ matrix.build_mode }} -j4
128 changes: 128 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: coverage

env:
COBERTURA_REPORT: cobertura.xml
COVERALLS_REPORT: coveralls.json
HTML_REPORT_DIR: html/
COVERAGE_ARTIFACT_NAME: coverage-report

on:
push:
branches: [master, development]
pull_request:
branches: [master, development]

jobs:
create-coverage-report:
runs-on: ubuntu-latest
container:
image: "ghcr.io/dnkpp/gcc:14"

steps:
- uses: actions/checkout@v4

- name: Install gcovr
run: |
python -m pip install gcovr
- name: Configure
env:
LDFLAGS: "-fprofile-arcs"
run: |
cmake -S . \
-B build \
-D CMAKE_CXX_FLAGS="-g -O0 --coverage -fno-inline -fprofile-abs-path -fkeep-inline-functions -fkeep-static-functions" \
-D CMAKE_BUILD_TYPE="Debug"
- name: Build
run: |
cmake --build build -j4
- name: Run tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest --test-dir build/test -C Debug -j4

- name: Run gcovr
run: |
# circumvnet "fatal: detected dubious ownership in repository" error
git config --global --add safe.directory /__w/mimicpp/mimicpp
gcovr --root build/test --filter "include/mimic++" --keep -j4 -v \
--exclude-lines-by-pattern "\s*assert\(" \
--exclude-unreachable-branches \
--exclude-noncode-lines \
--exclude-throw-branches \
--decisions \
--calls \
--cobertura ${{env.COBERTURA_REPORT}} --cobertura-pretty \
--html-nested ${{env.HTML_REPORT_DIR}} --html-title "mimic++ Coverage Report" \
--coveralls ${{env.COVERALLS_REPORT}} --coveralls-pretty
- name: Upload gcov coverage report artifacts
uses: actions/upload-artifact@v4
with:
name: gcov-files
path: "build/test/*.gcov"

- name: Upload generated report artifacts
uses: actions/upload-artifact@v4
with:
name: ${{env.COVERAGE_ARTIFACT_NAME}}
path: |
${{env.COBERTURA_REPORT}}
${{env.COVERALLS_REPORT}}
${{env.HTML_REPORT_DIR}}
codacy-report:
needs: create-coverage-report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{env.COVERAGE_ARTIFACT_NAME}}

- name: Upload coverage to Codacy
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{secrets.CODACY_PROJECT_TOKEN}}
coverage-reports: ${{env.COBERTURA_REPORT}}

codecov-report:
needs: create-coverage-report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{env.COVERAGE_ARTIFACT_NAME}}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
name: $GITHUB_REPOSITORY
token: ${{secrets.CODECOV_TOKEN}}
files: ${{env.COBERTURA_REPORT}}
fail_ci_if_error: true
verbose: true

coveralls-report:
needs: create-coverage-report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{env.COVERAGE_ARTIFACT_NAME}}

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
file: ${{env.COVERALLS_REPORT}}
format: coveralls
fail-on-error: true
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(get_cpm)

project(
mimic++
mimicpp
LANGUAGES CXX
)

CPMAddPackage(
NAME sanitizers-cmake
GITHUB_REPOSITORY "arsenm/sanitizers-cmake"
GIT_TAG "3f0542e4e034aab417c51b2b22c94f83355dee15"
SYSTEM YES
EXCLUDE_FROM_ALL YES
DOWNLOAD_ONLY YES
)
list(APPEND CMAKE_MODULE_PATH "${sanitizers-cmake_SOURCE_DIR}/cmake")
find_package(Sanitizers)

add_library(mimicpp INTERFACE)
add_library(mimicpp::mimicpp ALIAS mimicpp)
target_include_directories(
Expand All @@ -29,8 +40,12 @@ else()
set(IS_TOP_LEVEL_PROJECT OFF)
endif()

OPTION(mimicpp_BUILD_TESTS "Determines whether tests shall be built." ${IS_TOP_LEVEL_PROJECT})
if (mimicpp_BUILD_TESTS)
if (MIMICPP_FORCED_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${MIMICPP_FORCED_CXX_STANDARD})
endif()

OPTION(MIMICPP_BUILD_TESTS "Determines whether tests shall be built." ${IS_TOP_LEVEL_PROJECT})
if (MIMICPP_BUILD_TESTS)
include(CTest)
add_subdirectory("test")
endif()
Loading

0 comments on commit 79441bb

Please sign in to comment.