|
| 1 | +name: "Code Coverage" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'include/**.hpp' |
| 7 | + - 'test/**.cpp' |
| 8 | + - '**.cmake' |
| 9 | + - 'conanfile.py' |
| 10 | + - 'CMakeLists.txt' |
| 11 | + - 'test/CMakeLists.txt' |
| 12 | + - '.github/workflows/coverage.yml' |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - 'include/**.hpp' |
| 16 | + - 'test/**.cpp' |
| 17 | + - '**.cmake' |
| 18 | + - 'conanfile.py' |
| 19 | + - 'CMakeLists.txt' |
| 20 | + - 'test/CMakeLists.txt' |
| 21 | + - '.github/workflows/coverage.yml' |
| 22 | + |
| 23 | +jobs: |
| 24 | + coverage: |
| 25 | + name: Ubuntu ${{matrix.compiler.cc}} Coverage |
| 26 | + runs-on: ubuntu-20.04 |
| 27 | + |
| 28 | + env: |
| 29 | + build-directory: build |
| 30 | + |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + compiler: |
| 34 | + - { cc: gcc, cxx: g++, version: "10" } |
| 35 | + - { cc: clang, cxx: clang++, version: "10" } |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout repository |
| 39 | + uses: actions/checkout@v2 |
| 40 | + |
| 41 | + - name: Set up Python |
| 42 | + uses: actions/setup-python@v1 |
| 43 | + with: |
| 44 | + python-version: 3.7 |
| 45 | + |
| 46 | + - name: Prepare Environment |
| 47 | + run: | |
| 48 | + sudo apt-get install -y ${{matrix.compiler.cxx}}-${{matrix.compiler.version}} |
| 49 | + if [["${{matrix.compiler.cc}}" = "clang"]]; then |
| 50 | + sudo apt-get install -y llvm-${{matrix.compiler.version}} |
| 51 | + fi |
| 52 | + sudo apt-get install lcov |
| 53 | + python -m pip install --upgrade pip |
| 54 | + pip install conan |
| 55 | + cmake -E make_directory ${{env.build-directory}} |
| 56 | + cmake -E chdir ${{env.build-directory}} conan install .. |
| 57 | +
|
| 58 | + - name: Configure |
| 59 | + working-directory: ${{env.build-directory}} |
| 60 | + env: |
| 61 | + CC: ${{matrix.compiler.cc}}-${{matrix.compiler.version}} |
| 62 | + CXX: ${{matrix.compiler.cxx}}-${{matrix.compiler.version}} |
| 63 | + run: | |
| 64 | + cmake .. -DCMAKE_BUILD_TYPE=Debug \ |
| 65 | + -DBACKPORT_COMPILE_UNIT_TESTS=On \ |
| 66 | + -DCMAKE_CXX_FLAGS="--coverage -DBPSTD_INLINE_VISIBILITY=" \ |
| 67 | +
|
| 68 | + - name: Build |
| 69 | + working-directory: ${{env.build-directory}} |
| 70 | + run: cmake --build . |
| 71 | + |
| 72 | + - name: Test |
| 73 | + working-directory: ${{env.build-directory}} |
| 74 | + run: ctest --output-on-failure |
| 75 | + |
| 76 | + - name: Process Coverage Data |
| 77 | + working-directory: ${{env.build-directory}} |
| 78 | + run: | |
| 79 | + # Create a script for which gcov to use (needed for lcov) |
| 80 | + echo "#!/bin/bash" > gcov-executable.sh |
| 81 | + if [[ "${{matrix.compiler.cc}}" =~ "gcc" ]]; then |
| 82 | + echo 'gcov $@' >> gcov-executable.sh |
| 83 | + else |
| 84 | + echo 'llvm-cov-${{matrix.compiler.version}} gcov $@' >> gcov-executable.sh |
| 85 | + fi |
| 86 | + chmod +x gcov-executable.sh |
| 87 | + ./gcov-executable.sh $(find $(pwd) -name '*.o' -type f) |
| 88 | +
|
| 89 | + # Generate coverage information |
| 90 | + lcov --capture \ |
| 91 | + --gcov-tool $(pwd)/gcov-executable.sh \ |
| 92 | + --directory . \ |
| 93 | + --output-file coverage_unfiltered.info |
| 94 | +
|
| 95 | + # Strip symbols from 'test' directory |
| 96 | + lcov --remove coverage_unfiltered.info -o coverage.info \ |
| 97 | + --gcov-tool $(pwd)/gcov-executable.sh \ |
| 98 | + "$(cd ..; pwd)/test/*" \ |
| 99 | + "${HOME}/.conan/*" \ |
| 100 | + "/usr/*" \ |
| 101 | +
|
| 102 | + - name: Generate Coverage |
| 103 | + uses: coverallsapp/github-action@v1.1.2 |
| 104 | + with: |
| 105 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 106 | + path-to-lcov: ${{env.build-directory}}/coverage.info |
0 commit comments