Repository: provectus/kafka-ui
Issue: [Bug] fix sonar scans
Labels: type/bug
scope/infrastructure

Sonar scans were broken after recent workflow updates. Need to fix it.

Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml
index 573f1b08ac7..4cebf3557cb 100644
--- a/.github/workflows/backend.yml
+++ b/.github/workflows/backend.yml
@@ -1,13 +1,20 @@
 name: backend
 on:
+  push:
+    branches:
+      - master
   pull_request_target:
-    types: ['opened', 'edited', 'reopened', 'synchronize']
+    types: ["opened", "edited", "reopened", "synchronize"]
     paths:
-      - 'kafka-ui-api/**'
+      - "kafka-ui-api/**"
 jobs:
   build-and-test:
     runs-on: ubuntu-latest
     steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+          ref: ${{ github.event.pull_request.head.sha }}
       - name: Cache local Maven repository
         uses: actions/cache@v2
         with:
@@ -15,11 +22,6 @@ jobs:
           key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
           restore-keys: |
             ${{ runner.os }}-maven-
-      - uses: actions/checkout@v2
-      - name: compose app
-        id: step_five
-        run: |
-          docker-compose -f ./documentation/compose/kafka-ui.yaml up -d
       - name: Set up JDK 1.13
         uses: actions/setup-java@v1
         with:
@@ -30,9 +32,24 @@ jobs:
           path: ~/.sonar/cache
           key: ${{ runner.os }}-sonar
           restore-keys: ${{ runner.os }}-sonar
-      - name: Build and analyze
+      - name: Build and analyze pull request target
+        if: ${{ github.event_name == 'pull_request_target' }}
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
+        run: |
+          mvn versions:set -DnewVersion=${{ github.event.pull_request.head.sha }}
+          mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
+          -Dsonar.projectKey=com.provectus:kafka-ui_backend \
+          -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
+          -Dsonar.pullrequest.branch=${{ github.head_ref }} \
+          -Dsonar.pullrequest.base=${{ github.base_ref }}
+      - name: Build and analyze push master
+        if: ${{ github.event_name == 'push' }}
         env:
-          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
         run: |
           mvn versions:set -DnewVersion=$GITHUB_SHA
-          mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
+          mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
+          -Dsonar.projectKey=com.provectus:kafka-ui_backend
diff --git a/.github/workflows/e2e-checks.yaml b/.github/workflows/e2e-checks.yaml
index 9145b32ca6d..832b07c85c8 100644
--- a/.github/workflows/e2e-checks.yaml
+++ b/.github/workflows/e2e-checks.yaml
@@ -1,16 +1,19 @@
 name: e2e-checks
 on:
   pull_request_target:
-    types: [ 'opened', 'edited', 'reopened', 'synchronize' ]
+    types: ["opened", "edited", "reopened", "synchronize"]
     paths:
-      - 'kafka-ui-api/**'
-      - 'kafka-ui-contract/**'
-      - 'kafka-ui-react-app/**'
-      - 'kafka-ui-e2e-checks/**'
+      - "kafka-ui-api/**"
+      - "kafka-ui-contract/**"
+      - "kafka-ui-react-app/**"
+      - "kafka-ui-e2e-checks/**"
 jobs:
   build-and-test:
     runs-on: ubuntu-latest
     steps:
+      - uses: actions/checkout@v2
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
       - name: Cache local Maven repository
         uses: actions/cache@v2
         with:
@@ -18,7 +21,6 @@ jobs:
           key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
           restore-keys: |
             ${{ runner.os }}-maven-
-      - uses: actions/checkout@v2
       - name: Set the values
         id: set_env_values
         run: |
@@ -34,7 +36,7 @@ jobs:
       - name: Build with Maven
         id: build_app
         run: |
-          mvn versions:set -DnewVersion=$GITHUB_SHA
+          mvn versions:set -DnewVersion=${{ github.event.pull_request.head.sha }}
           mvn clean package -DskipTests ${{ github.event.inputs.extraMavenOptions }}
       - name: compose app
         id: compose_app
@@ -43,7 +45,7 @@ jobs:
           docker-compose -f ./documentation/compose/kafka-ui-connectors.yaml up -d
       - name: e2e run
         run: |
-          mvn versions:set -DnewVersion=$GITHUB_SHA
+          mvn versions:set -DnewVersion=${{ github.event.pull_request.head.sha }}
           mvn -pl '!kafka-ui-api' test -Pprod
       - name: Generate allure report
         uses: simple-elf/allure-report-action@master
@@ -67,8 +69,8 @@ jobs:
         uses: Sibz/github-status-action@v1.1.6
         with:
           authToken: ${{secrets.GITHUB_TOKEN}}
-          context: 'Test report'
-          state: 'success'
+          context: "Test report"
+          state: "success"
           sha: ${{ github.event.pull_request.head.sha  || github.sha }}
           target_url: https://${{ github.repository_owner }}.github.io/kafka-ui/allure/allure-results/${{ github.run_number }}
       - name: Dump docker logs on failure
diff --git a/.github/workflows/frontend.yaml b/.github/workflows/frontend.yaml
index 631981d1ed9..7dd97ebea7a 100644
--- a/.github/workflows/frontend.yaml
+++ b/.github/workflows/frontend.yaml
@@ -4,10 +4,10 @@ on:
     branches:
       - master
   pull_request_target:
-    types: ['opened', 'edited', 'reopened', 'synchronize']
+    types: ["opened", "edited", "reopened", "synchronize"]
     paths:
-    - 'kafka-ui-contract/**'
-    - 'kafka-ui-react-app/**'
+      - "kafka-ui-contract/**"
+      - "kafka-ui-react-app/**"
 jobs:
   build-and-test:
     env:
@@ -15,41 +15,43 @@ jobs:
       NODE_ENV: dev
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v2
-      with:
-        # Disabling shallow clone is recommended for improving relevancy of reporting
-        fetch-depth: 0
-    - name: Use Node.js
-      uses: actions/setup-node@v1
-      with:
-        node-version: "14"
-    - name: Cache node dependency
-      uses: actions/cache@v1
-      with:
-        path: kafka-ui-react-app/node_modules
-        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
-        restore-keys: |
-          ${{ runner.os }}-node-
-    - name: Install Node dependencies
-      run: |
-        cd kafka-ui-react-app/
-        npm install
-    - name: Generate sources
-      run: |
-        cd kafka-ui-react-app/
-        npm run gen:sources
-    - name: Linter
-      run: |
-        cd kafka-ui-react-app/
-        npm run lint
-    - name: Tests
-      run: |
-        cd kafka-ui-react-app/
-        npm run test:CI
-    - name: SonarCloud Scan
-      uses: workshur/sonarcloud-github-action@improved_basedir
-      with:
-        projectBaseDir: ./kafka-ui-react-app
-      env:
-        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
+      - uses: actions/checkout@v2
+        with:
+          # Disabling shallow clone is recommended for improving relevancy of reporting
+          fetch-depth: 0
+          ref: ${{ github.event.pull_request.head.sha }}
+      - name: Use Node.js
+        uses: actions/setup-node@v1
+        with:
+          node-version: "14"
+      - name: Cache node dependency
+        uses: actions/cache@v1
+        with:
+          path: kafka-ui-react-app/node_modules
+          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+          restore-keys: |
+            ${{ runner.os }}-node-
+      - name: Install Node dependencies
+        run: |
+          cd kafka-ui-react-app/
+          npm install
+      - name: Generate sources
+        run: |
+          cd kafka-ui-react-app/
+          npm run gen:sources
+      - name: Linter
+        run: |
+          cd kafka-ui-react-app/
+          npm run lint
+      - name: Tests
+        run: |
+          cd kafka-ui-react-app/
+          npm run test:CI
+      - name: SonarCloud Scan
+        uses: workshur/sonarcloud-github-action@improved_basedir
+        with:
+          projectBaseDir: ./kafka-ui-react-app
+          args: -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }}
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml
index 48b47c5196f..74ff75b833d 100644
--- a/.github/workflows/pr-checks.yaml
+++ b/.github/workflows/pr-checks.yaml
@@ -1,7 +1,7 @@
-name: 'PR Checklist checked'
+name: "PR Checklist checked"
 on:
   pull_request_target:
-    types: [opened, edited, synchronized, reopened]
+    types: [opened, edited, synchronize, reopened]
 
 jobs:
   task-check:
@@ -12,4 +12,4 @@ jobs:
           repo-token: "${{ secrets.GITHUB_TOKEN }}"
       - uses: dekinderfiets/pr-description-enforcer@0.0.1
         with:
-          repo-token: '${{ secrets.GITHUB_TOKEN }}'
+          repo-token: "${{ secrets.GITHUB_TOKEN }}"
diff --git a/kafka-ui-react-app/sonar-project.properties b/kafka-ui-react-app/sonar-project.properties
index ecab3f4713a..2275c2e2383 100644
--- a/kafka-ui-react-app/sonar-project.properties
+++ b/kafka-ui-react-app/sonar-project.properties
@@ -1,4 +1,4 @@
-sonar.projectKey=provectus_kafka-ui_frontend
+sonar.projectKey=com.provectus:kafka-ui_frontend
 sonar.organization=provectus
 
 sonar.sources=.


Test patch: