Skip to content

Commit

Permalink
Merge pull request #1452 from tier4/fix/sonar-cloud-coverage-chris
Browse files Browse the repository at this point in the history
fix(sonar): sonar cloud coverage
  • Loading branch information
hakuturu583 authored Nov 18, 2024
2 parents 2ddff4d + 3278e6f commit bbe0fa0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/BuildAndRun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Resolve rosdep and install colcon mixin
run: |
apt-get update
apt-get install -y python3-pip python3-colcon-lcov-result lcov unzip
apt-get install -y python3-pip python3-colcon-lcov-result lcov unzip gcovr
rosdep update --include-eol-distros
rosdep install -iy --from-paths src --rosdistro ${{ matrix.rosdistro }}
colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
Expand All @@ -84,7 +84,14 @@ jobs:
run: |
source /opt/ros/${{ matrix.rosdistro }}/setup.bash
build-wrapper-linux-x86-64 --out-dir src/scenario_simulator_v2/bw-output \
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} -DBUILD_CPP_MOCK_SCENARIOS=ON -DBUILD_TESTING=true -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' -DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage' --packages-up-to ${{ steps.list_packages.outputs.package_list }}
colcon build --symlink-install \
--cmake-args \
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
-DBUILD_CPP_MOCK_SCENARIOS=ON \
-DBUILD_TESTING=true \
-DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' \
-DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage' \
--packages-up-to ${{ steps.list_packages.outputs.package_list }}
shell: bash

- name: Colcon test
Expand All @@ -95,14 +102,8 @@ jobs:
colcon lcov-result --packages-select ${{ steps.list_packages.outputs.package_list }}
shell: bash

- name: Collect and run gcov on coverage data
run: |
mkdir -p ./gcov && \
find ./build -name "*.gcda" -o -name "*.gcno" | \
while read -r line; do \
gcov -o $(dirname "$line") $(echo "$line" | sed 's/\.gcda$/.cpp/;s/\.gcno$/.cpp/;s/\.gcda$/.hpp/;s/\.gcno$/.hpp/'); \
done && mv *.gcov ./gcov/
- name: generate gcov report for sonarcloud
run: gcovr -r src/scenario_simulator_v2 build --sonarqube coverage.xml

- name: Show test result
if: always()
Expand All @@ -126,6 +127,13 @@ jobs:
path: lcov
retention-days: 1

- name: Upload Gcov result
uses: actions/upload-artifact@v4
with:
name: coverage${{ matrix.cmake_build_type }}.xml
path: coverage.xml
retention-days: 1

- name: Run SonarCloud scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/custom_spell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"euclidian",
"gcda",
"gcno",
"gcovr",
"libunwind",
"linelint",
"Mersenne",
Expand All @@ -37,6 +38,8 @@
"pyproject",
"randomizer",
"randomizers",
"sonarcloud",
"sonarqube",
"subspline",
"TESTRANDOMIZER",
"travelling",
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ sonar.exclusions=**/test/**,**/mock/**
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

#~/scenario_simulator_ws/gcov
sonar.cfamily.gcov.reportsPath=../../gcov/
#~/scenario_simulator_ws/coverage.xml
sonar.coverageReportPaths=../../coverage.xml

0 comments on commit bbe0fa0

Please # to comment.