From dcf9b3cca6188422dd7ee82b16de060059322b87 Mon Sep 17 00:00:00 2001 From: Tyler Weaver Date: Mon, 22 May 2023 14:24:29 -0600 Subject: [PATCH] Run SonarCloud only on push (#2189) --- .github/workflows/ci.yaml | 14 +---- .github/workflows/sonar.yaml | 117 +++++++++++++++++++++++++++++++++++ sonar-project.properties | 4 +- 3 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/sonar.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 227c70d537..8a58adcb94 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,8 +49,6 @@ jobs: # Changing linker to lld as ld has a behavior where it takes a long time to finish # Compile CCOV with Debug. Enable -Werror. TARGET_CMAKE_ARGS: > - --no-warn-unused-cli - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld @@ -76,7 +74,7 @@ jobs: - name: "Free up disk space" if: matrix.env.CCOV run: | - sudo apt-get -qq purge build-essential "ghc*" + sudo apt-get -qq purge "ghc*" sudo apt-get clean # cleanup docker images not used by us docker system prune -af @@ -164,16 +162,6 @@ jobs: if: always() && matrix.env.CCOV && steps.ici.outputs.target_test_results == '0' with: files: ${{ env.BASEDIR }}/target_ws/coverage.info - - name: Install sonar-scanner and build-wrapper - if: always() && matrix.env.CCOV && steps.ici.outputs.target_test_results == '0' - uses: SonarSource/sonarcloud-github-c-cpp@v1 - - name: Run sonar-scanner - if: always() && matrix.env.CCOV && steps.ici.outputs.target_test_results == '0' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: sonar-scanner -X --define project.settings=.work/target_ws/src/moveit2/sonar-project.properties - working-directory: ${{ github.workspace }} - name: Upload clang-tidy changes uses: rhaschke/upload-git-patch-action@main if: always() && matrix.env.CLANG_TIDY diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml new file mode 100644 index 0000000000..d50f260e98 --- /dev/null +++ b/.github/workflows/sonar.yaml @@ -0,0 +1,117 @@ +# This config uses industrial_ci (https://github.com/ros-industrial/industrial_ci.git). +# For troubleshooting, see readme (https://github.com/ros-industrial/industrial_ci/blob/master/README.rst) + +name: SonarScan + +on: + push: + +jobs: + default: + env: + ROS_DISTRO: rolling + CXXFLAGS: >- + -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls + CLANG_TIDY_ARGS: --fix --fix-errors --format-style=file + DOCKER_IMAGE: moveit/moveit2:rolling-ci + UPSTREAM_WORKSPACE: > + moveit2.repos + $(f="moveit2_$(sed 's/-.*$//' <<< "rolling-ci").repos"; test -r $f && echo $f) + # Pull any updates to the upstream workspace (after restoring it from cache) + AFTER_SETUP_UPSTREAM_WORKSPACE: vcs pull $BASEDIR/upstream_ws/src + AFTER_SETUP_DOWNSTREAM_WORKSPACE: vcs pull $BASEDIR/downstream_ws/src + # Clear the ccache stats before and log the stats after the build + AFTER_SETUP_CCACHE: ccache --zero-stats --max-size=10.0G + BEFORE_BUILD_UPSTREAM_WORKSPACE: ccache -z + AFTER_BUILD_TARGET_WORKSPACE: ccache -s + TARGET_CMAKE_ARGS: > + --no-warn-unused-cli + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld + -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld + -DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld + -DCMAKE_BUILD_TYPE='Debug' + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS --coverage -O2 -fno-omit-frame-pointer" + UPSTREAM_CMAKE_ARGS: "-DCMAKE_CXX_FLAGS=''" + DOWNSTREAM_CMAKE_ARGS: -DCMAKE_CXX_FLAGS="-Wall -Wextra" + CCACHE_DIR: ${{ github.workspace }}/.ccache + BASEDIR: ${{ github.workspace }}/.work + ADDITIONAL_DEBS: lld + + name: rolling-ci-ccov-sonar + runs-on: ubuntu-latest + steps: + - name: "Free up disk space" + if: matrix.env.CCOV + run: | + sudo apt-get -qq purge "ghc*" + sudo apt-get clean + # cleanup docker images not used by us + docker system prune -af + # shift ccache folder to /mnt on a separate disk + sudo mkdir /mnt/ccache + mkdir ${{ env.CCACHE_DIR }} + sudo mount --bind ${{ env.CCACHE_DIR }} /mnt/ccache + # free up a lot of stuff from /usr/local + sudo rm -rf /usr/local + df -h + - uses: actions/checkout@v3 + - uses: testspace-com/setup-testspace@v1 + if: github.repository == 'ros-planning/moveit2' + with: + domain: ros-planning + - name: Get latest release date for rosdistro + id: rosdistro_release_date + uses: JafarAbdi/latest-rosdistro-release-date-action@main + with: + rosdistro: ${{ env.ROS_DISTRO }} + - name: Get latest timestamp repos file has been edited + id: repos_edit_timestamp + uses: vatanaksoytezer/latest-file-edit-timestamp-action@main + with: + file: moveit2.repos + - name: Cache upstream workspace + uses: pat-s/always-upload-cache@v3.0.11 + with: + path: ${{ env.BASEDIR }}/upstream_ws + key: ${{ env.CACHE_PREFIX }}-${{ github.run_id }} + restore-keys: ${{ env.CACHE_PREFIX }} + env: + CACHE_PREFIX: ${{ steps.rosdistro_release_date.outputs.date }}-upstream_ws-${{ steps.repos_edit_timestamp.outputs.timestamp }}-rolling-ci-${{ hashFiles('moveit2*.repos', '.github/workflows/ci.yaml') }} + - name: Cache ccache + uses: pat-s/always-upload-cache@v3.0.11 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-rolling-ci-ccov-${{ github.sha }}-${{ github.run_id }} + restore-keys: | + ccache-rolling-ci-ccov-${{ github.sha }} + ccache-rolling-ci-ccov + - name: Configure ccache + run: | + mkdir -p ${{ env.CCACHE_DIR }} + cp .github/ccache.conf ${{ env.CCACHE_DIR }}/ccache.conf + - id: ici + name: Run industrial_ci + uses: ros-industrial/industrial_ci@master + - name: Generate codecov report + uses: rhaschke/lcov-action@main + if: steps.ici.outputs.target_test_results == '0' + with: + docker: $DOCKER_IMAGE + workdir: ${{ env.BASEDIR }}/target_ws + ignore: '"*/target_ws/build/*" "*/target_ws/install/*" "*/test/*"' + - name: Install ccache + run: sudo apt install ccache build-essential + - name: Print coverage.info + if: steps.ici.outputs.target_test_results == '0' + run: cat ${{ github.workspace }}/.work/target_ws/coverage.info + - name: Install sonar-scanner + if: steps.ici.outputs.target_test_results == '0' + uses: SonarSource/sonarcloud-github-c-cpp@v1 + - name: Run sonar-scanner + if: steps.ici.outputs.target_test_results == '0' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: sonar-scanner -X --define project.settings=.work/target_ws/src/moveit2/sonar-project.properties + working-directory: ${{ github.workspace }} diff --git a/sonar-project.properties b/sonar-project.properties index bde20ee807..ec74264201 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,5 +3,7 @@ sonar.organization=moveit sonar.python.version=3 sonar.sources=.work/target_ws/src - +sonar.cfamily.llvm-cov.reportPath=.work/target_ws/coverage.info +sonar.scm.exclusions.disabled=true +sonar.exclusions=.work/target_ws/src/moveit2/moveit_planners/test_configs/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_solver.cpp sonar.cfamily.compile-commands=.work/target_ws/build/compile_commands.json