From dbd9a4616449972c55e9eb683520891fb52e5a60 Mon Sep 17 00:00:00 2001 From: Dorian Eikenberg Date: Mon, 27 Mar 2023 16:31:06 +0200 Subject: [PATCH] Add SonarCloud integration --- .../workflows/codacy-clang-tidy-upload.yml | 50 ---------- .github/workflows/codacy-coverage-upload.yml | 44 --------- .github/workflows/cpp-lint-thorough.yml | 77 --------------- .github/workflows/cpp-lint.yml | 78 --------------- .github/workflows/cpp.yml | 94 +------------------ .github/workflows/sonar-scanner.yml | 91 ++++++++++++++++++ .../inmemoryscanner/sonar-project.properties | 6 ++ vmicore/sonar-project.properties | 5 + 8 files changed, 106 insertions(+), 339 deletions(-) delete mode 100644 .github/workflows/codacy-clang-tidy-upload.yml delete mode 100644 .github/workflows/codacy-coverage-upload.yml delete mode 100644 .github/workflows/cpp-lint-thorough.yml delete mode 100644 .github/workflows/cpp-lint.yml create mode 100644 .github/workflows/sonar-scanner.yml create mode 100644 plugins/inmemoryscanner/sonar-project.properties create mode 100644 vmicore/sonar-project.properties diff --git a/.github/workflows/codacy-clang-tidy-upload.yml b/.github/workflows/codacy-clang-tidy-upload.yml deleted file mode 100644 index e1f239f6..00000000 --- a/.github/workflows/codacy-clang-tidy-upload.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -name: Codacy Clang Tidy Upload - -on: - workflow_run: - workflows: [CPP Lint, CPP Thorough Lint] - types: - - completed - -jobs: - clang_tidy_upload: - runs-on: ubuntu-latest - # Required because codacy's conversion tool relativizes paths in respect to the current working directory. - # Since the project path inside a container is different from the path inside a "raw" worker VM we need to - # make sure that we match the environment where the clang-tidy output was created (though any container - # image would do, most likely). - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - name: Download clang-tidy artifact - uses: actions/github-script@v6 - with: - script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "clang_tidy_all" - })[0]; - let download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/clang_tidy_all.zip`, Buffer.from(download.data)); - - - run: unzip -j clang_tidy_all.zip - - - name: Run Codacy Analysis CLI - uses: rageagainsthepc/codacy-analysis-cli-action@fix-action-path - with: - run-docker-tools: false - clang-tidy-output: clang-tidy-output - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - upload: true diff --git a/.github/workflows/codacy-coverage-upload.yml b/.github/workflows/codacy-coverage-upload.yml deleted file mode 100644 index bb481f5c..00000000 --- a/.github/workflows/codacy-coverage-upload.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -name: Codacy Coverage Upload - -on: - workflow_run: - workflows: [CPP CI] - types: - - completed - -jobs: - test_coverage_upload: - runs-on: ubuntu-latest - - steps: - - name: Download coverage artifact - uses: actions/github-script@v6 - with: - script: | - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "coverage_all" - })[0]; - let download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/coverage_all.zip`, Buffer.from(download.data)); - - - run: unzip -j coverage_all.zip - - - name: Run codacy-coverage-reporter - uses: codacy/codacy-coverage-reporter-action@v1 - with: - project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: cobertura.xml - language: CPP - force-coverage-parser: cobertura diff --git a/.github/workflows/cpp-lint-thorough.yml b/.github/workflows/cpp-lint-thorough.yml deleted file mode 100644 index 0ecf6af2..00000000 --- a/.github/workflows/cpp-lint-thorough.yml +++ /dev/null @@ -1,77 +0,0 @@ ---- -name: CPP Thorough Lint - -on: workflow_dispatch - -jobs: - lint_core: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Configure vmicore - run: cmake --preset clang-debug - working-directory: vmicore - - - name: Generate clang-tidy output for codacy - run: clang-tidy -p build-clang-debug/ $(find src/ -iname *.h -o -iname *.cpp) > clang-tidy-output - working-directory: vmicore - - - name: Upload clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_vmicore - path: vmicore/clang-tidy-output - - lint_inmemoryscanner: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Configure inmemoryscanner - run: cmake --preset clang-debug - working-directory: plugins/inmemoryscanner - - - name: Generate clang-tidy output for codacy - run: clang-tidy -p build-clang-debug/ $(find src/ -iname *.h -o -iname *.cpp) > clang-tidy-output - working-directory: plugins/inmemoryscanner - - - name: Upload clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_inmemoryscanner - path: plugins/inmemoryscanner/clang-tidy-output - - consolidate_output: - needs: [lint_core, lint_inmemoryscanner] - runs-on: ubuntu-latest - - steps: - - name: Download vmicore clang-tidy artifact - uses: actions/download-artifact@v3 - with: - name: clang_tidy_vmicore - path: vmicore - - - name: Download inmemoryscanner clang-tidy artifact - uses: actions/download-artifact@v3 - with: - name: clang_tidy_inmemoryscanner - path: plugins/inmemoryscanner - - - name: Consolidate clang-tidy output - run: | - cat vmicore/clang-tidy-output > clang-tidy-output - cat plugins/inmemoryscanner/clang-tidy-output >> clang-tidy-output - - - name: Upload consolidated clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_all - path: clang-tidy-output diff --git a/.github/workflows/cpp-lint.yml b/.github/workflows/cpp-lint.yml deleted file mode 100644 index 9d30ea05..00000000 --- a/.github/workflows/cpp-lint.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -name: CPP Lint - -on: - pull_request: - branches: - - "main" - -jobs: - lint_core: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Configure vmicore - run: cmake --preset clang-debug - working-directory: vmicore - - - name: Generate clang-tidy output for codacy - run: git diff ${GITHUB_BASE_REF} | $(find /usr/lib/ -name clang-tidy-diff.py) -j 4 -p 1 -path vmicore/build-clang-debug/ -regex '.*vmicore\/src.*(\.h|\.cpp)' > clang-tidy-output - - - name: Upload clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_vmicore - path: clang-tidy-output - - lint_inmemoryscanner: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Configure inmemoryscanner - run: cmake --preset clang-debug - working-directory: plugins/inmemoryscanner - - - name: Generate clang-tidy output for codacy - run: git diff ${GITHUB_BASE_REF} | $(find /usr/lib/ -name clang-tidy-diff.py) -j 4 -p 1 -path plugins/inmemoryscanner/build-clang-debug/ -regex '.*inmemoryscanner\/src.*(\.h|\.cpp)' > clang-tidy-output - - - name: Upload clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_inmemoryscanner - path: clang-tidy-output - - consolidate_output: - needs: [lint_core, lint_inmemoryscanner] - runs-on: ubuntu-latest - - steps: - - name: Download vmicore clang-tidy artifact - uses: actions/download-artifact@v3 - with: - name: clang_tidy_vmicore - path: vmicore - - - name: Download inmemoryscanner clang-tidy artifact - uses: actions/download-artifact@v3 - with: - name: clang_tidy_inmemoryscanner - path: plugins/inmemoryscanner - - - name: Consolidate clang-tidy output - run: | - cat vmicore/clang-tidy-output > clang-tidy-output - cat plugins/inmemoryscanner/clang-tidy-output >> clang-tidy-output - - - name: Upload consolidated clang-tidy artifact - uses: actions/upload-artifact@v3 - with: - name: clang_tidy_all - path: clang-tidy-output diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 068939a6..ff6f2bbf 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -5,23 +5,9 @@ on: push: branches: - "main" - paths: - - '**.h' - - '**.cpp' - - '**/CMakeLists.txt' - - '**/CMakePresets.json' - - '**/.clang-tidy' - - '**/.clang-format' pull_request: branches: - "main" - paths: - - '**.h' - - '**.cpp' - - '**/CMakeLists.txt' - - '**/CMakePresets.json' - - '**/.clang-tidy' - - '**/.clang-format' jobs: format: @@ -35,29 +21,6 @@ jobs: - name: Perform C++ format check run: find . -iname *.h -o -iname *.cpp | xargs clang-format --style=file --dry-run --Werror - test_core: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Test vmicore - run: | - cmake --preset gcc-debug -D VMICORE_TEST_COVERAGE:BOOL=ON - cmake --build --preset gcc-build-debug --target vmicore-test - ctest --preset gcc-test - cd build-gcc-debug - gcovr -r ${GITHUB_WORKSPACE} --json coverage.json - working-directory: vmicore - - - name: Upload coverage artifact - uses: actions/upload-artifact@v3 - with: - name: coverage_vmicore - path: vmicore/build-gcc-debug/coverage.json - build_core: runs-on: ubuntu-latest container: @@ -66,35 +29,13 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build vmicore + - name: Build and test vmicore run: | cmake --preset clang-debug cmake --build --preset clang-build-debug + ctest --preset clang-test working-directory: vmicore - test_inmemoryscanner: - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - uses: actions/checkout@v3 - - - name: Test inmemoryscanner - run: | - cmake --preset gcc-debug -D INMEMORYSCANNER_TEST_COVERAGE:BOOL=ON - cmake --build --preset gcc-build-debug --target inmemoryscanner-test - ctest --preset gcc-test - cd build-gcc-debug - gcovr -r ${GITHUB_WORKSPACE} --json coverage.json - working-directory: plugins/inmemoryscanner - - - name: Upload coverage artifact - uses: actions/upload-artifact@v3 - with: - name: coverage_inmemoryscanner - path: plugins/inmemoryscanner/build-gcc-debug/coverage.json - build_inmemoryscanner: runs-on: ubuntu-latest container: @@ -103,36 +44,9 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build inmemoryscanner + - name: Build and test inmemoryscanner run: | cmake --preset clang-debug cmake --build --preset clang-build-debug + ctest --preset clang-test working-directory: plugins/inmemoryscanner - - consolidate_coverage_reports: - needs: [test_core, test_inmemoryscanner] - runs-on: ubuntu-latest - container: - image: ghcr.io/gdatasoftwareag/vmi-build - - steps: - - name: Download vmicore coverage artifact - uses: actions/download-artifact@v3 - with: - name: coverage_vmicore - path: vmicore - - - name: Download inmemoryscanner coverage artifact - uses: actions/download-artifact@v3 - with: - name: coverage_inmemoryscanner - path: plugins/inmemoryscanner - - - name: Generate combined cobertura.xml - run: gcovr -a vmicore/coverage.json -a plugins/inmemoryscanner/coverage.json --xml cobertura.xml - - - name: Upload coverage artifact - uses: actions/upload-artifact@v3 - with: - name: coverage_all - path: cobertura.xml diff --git a/.github/workflows/sonar-scanner.yml b/.github/workflows/sonar-scanner.yml new file mode 100644 index 00000000..2d7f9e4c --- /dev/null +++ b/.github/workflows/sonar-scanner.yml @@ -0,0 +1,91 @@ +--- +name: Sonar Scanner + +on: + workflow_run: + workflows: [CPP CI] + types: + - in_progress + +jobs: + vmicore_sonar_scanner: + runs-on: ubuntu-latest + # Replicate build environment (path sctructure) + container: + image: ghcr.io/gdatasoftwareag/vmi-build + env: + BUILD_WRAPPER_OUT_DIR: sonar/ + + steps: + - uses: actions/checkout@v3 + with: + repository: ${{ github.event.workflow_run.head_repository.full_name }} + ref: ${{ github.event.workflow_run.head_branch }} + fetch-depth: 0 + + - name: Install sonar-scanner + uses: SonarSource/sonarcloud-github-c-cpp@v1 + + - name: Build and test vmicore + run: | + cmake --preset gcc-debug -D VMICORE_TEST_COVERAGE:BOOL=ON + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build --preset gcc-build-debug + ctest --preset gcc-test + cd build-gcc-debug + gcovr -r .. --sonarqube > ../coverage.xml + working-directory: vmicore + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner \ + -D sonar.cfamily.build-wrapper-output=${{ env.BUILD_WRAPPER_OUT_DIR }} \ + -D sonar.coverageReportPaths=coverage.xml \ + -D sonar.scm.revision=${{ github.event.workflow_run.head_sha }} \ + -D sonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} \ + -D sonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} \ + -D sonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} + working-directory: vmicore/ + + inmemoryscanner_sonar_scanner: + runs-on: ubuntu-latest + # Replicate build environment (path sctructure) + container: + image: ghcr.io/gdatasoftwareag/vmi-build + env: + BUILD_WRAPPER_OUT_DIR: sonar/ + + steps: + - uses: actions/checkout@v3 + with: + repository: ${{ github.event.workflow_run.head_repository.full_name }} + ref: ${{ github.event.workflow_run.head_branch }} + fetch-depth: 0 + + - name: Install sonar-scanner + uses: SonarSource/sonarcloud-github-c-cpp@v1 + + - name: Build and test inmemoryscanner + run: | + cmake --preset gcc-debug -D INMEMORYSCANNER_TEST_COVERAGE:BOOL=ON + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build --preset gcc-build-debug + ctest --preset gcc-test + cd build-gcc-debug + gcovr -r .. --sonarqube > ../coverage.xml + working-directory: plugins/inmemoryscanner + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner \ + -D sonar.cfamily.build-wrapper-output=${{ env.BUILD_WRAPPER_OUT_DIR }} \ + -D sonar.coverageReportPaths=coverage.xml \ + -D sonar.scm.revision=${{ github.event.workflow_run.head_sha }} \ + -D sonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} \ + -D sonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} \ + -D sonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} + working-directory: plugins/inmemoryscanner/ diff --git a/plugins/inmemoryscanner/sonar-project.properties b/plugins/inmemoryscanner/sonar-project.properties new file mode 100644 index 00000000..afc571df --- /dev/null +++ b/plugins/inmemoryscanner/sonar-project.properties @@ -0,0 +1,6 @@ +sonar.projectKey=gdatasoftwareag_inmemory +sonar.organization=gdatasoftwareag +sonar.projectName=InMemoryScanner Plugin +sonar.sources=src +sonar.tests=test +sonar.exclusions=src/lib/rapidxml/* diff --git a/vmicore/sonar-project.properties b/vmicore/sonar-project.properties new file mode 100644 index 00000000..aca72e07 --- /dev/null +++ b/vmicore/sonar-project.properties @@ -0,0 +1,5 @@ +sonar.projectKey=gdatasoftwareag_smartvmi_vmicore +sonar.organization=gdatasoftwareag +sonar.projectName=VMICore +sonar.sources=src +sonar.tests=test