Repository: sogno-platform/dpsim (language: python)

Issue:
Sonar cloud CI
Enable sonar cloud scan for C++ code.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/sonar_cloud.yaml b/.github/workflows/sonar_cloud.yaml
new file mode 100644
index 0000000000..6877f5188d
--- /dev/null
+++ b/.github/workflows/sonar_cloud.yaml
@@ -0,0 +1,58 @@
+name: Sonar Cloud Analysis
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened]
+jobs:
+  build:
+    name: Analyse with Sonar Cloud
+    runs-on: ubuntu-latest
+    container: sogno/dpsim:dev
+    env:
+      SONAR_SCANNER_VERSION: 4.7.0.2747
+      SONAR_SERVER_URL: "https://sonarcloud.io"
+      BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
+      - name: Set up JDK 11
+        uses: actions/setup-java@v1
+        with:
+          java-version: 11
+      - name: Download and set up sonar-scanner
+        env:
+          SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
+        run: |
+          mkdir -p $HOME/.sonar
+          curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} 
+          unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
+          echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
+      - name: Download and set up build-wrapper
+        env:
+          BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip
+        run: |
+          curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
+          unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+          echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
+      - name: Setup sonar cache
+        uses: actions/cache@v2
+        with:
+          path: ${{ github.workspace }}/sonar-cache
+          key: sonar-cache-${{ github.ref }}
+      - name: Create Build Folder
+        run: mkdir build
+      - name: Configure CMake
+        shell: bash
+        working-directory: ${{ github.workspace }}/build
+        run: |
+          cmake -DCIM_VERSION=CGMES_2.4.15_16FEB2016 $GITHUB_WORKSPACE
+      - name: Run build-wrapper
+        run: |
+          build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/
+      - name: Run sonar-scanner
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+        run: |
+          sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
\ No newline at end of file
diff --git a/sonar-project.properties b/sonar-project.properties
new file mode 100644
index 0000000000..3f6154dc8a
--- /dev/null
+++ b/sonar-project.properties
@@ -0,0 +1,23 @@
+sonar.projectKey=sogno-platform_dpsim
+sonar.organization=sogno-platform
+
+# Cpp analysis settings
+sonar.cfamily.threads=2
+sonar.cfamily.cache.enabled=true
+sonar.cfamily.cache.path=sonar-cache
+
+# Sonar Python Version
+sonar.python.version=3.7, 3.8, 3.9, 3.10
+
+# Patterns excluded from duplication detection
+sonar.cpd.exclusions=Examples/**/*
+
+# This is the name and version displayed in the SonarCloud UI.
+sonar.projectName=DPsim
+sonar.projectVersion=1.1.0
+
+# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
+#sonar.sources=.
+
+# Encoding of the source code. Default is default system encoding
+#sonar.sourceEncoding=UTF-8


Test patch:
diff --git a/.github/workflows/build_test_linux_centos.yaml b/.github/workflows/build_test_linux_centos.yaml
index a039f1789b..ba6346c62e 100644
--- a/.github/workflows/build_test_linux_centos.yaml
+++ b/.github/workflows/build_test_linux_centos.yaml
@@ -1,6 +1,9 @@
 name: Build & Test CentOS
 
-on: push
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened]
 
 ## Build ##
 
diff --git a/.github/workflows/build_test_linux_fedora.yaml b/.github/workflows/build_test_linux_fedora.yaml
index 4660de002d..c51b598fe3 100644
--- a/.github/workflows/build_test_linux_fedora.yaml
+++ b/.github/workflows/build_test_linux_fedora.yaml
@@ -1,6 +1,9 @@
 name: Build & Test Fedora
 
-on: push
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened]
 
 ## Build ##
 
diff --git a/.github/workflows/build_test_linux_fedora_minimal.yaml b/.github/workflows/build_test_linux_fedora_minimal.yaml
index 7350e6f6a5..ad9ff8aa5c 100644
--- a/.github/workflows/build_test_linux_fedora_minimal.yaml
+++ b/.github/workflows/build_test_linux_fedora_minimal.yaml
@@ -1,6 +1,9 @@
 name: Build & Test Fedora Minimal
 
-on: push
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened]
 
 ## Build ##
 
diff --git a/.github/workflows/build_test_windows.yaml b/.github/workflows/build_test_windows.yaml
index e999dcafbf..a0f995ccf2 100644
--- a/.github/workflows/build_test_windows.yaml
+++ b/.github/workflows/build_test_windows.yaml
@@ -1,6 +1,9 @@
 name: Build & Test Windows
 
-on: push
+on:
+  push:
+  pull_request:
+    types: [opened, synchronize, reopened]
 
 ## Build ##