From 5c965cfcaffef99ab9ff3c865233e8f96cdc9447 Mon Sep 17 00:00:00 2001 From: Rajendra Reddy Date: Mon, 30 Mar 2026 03:41:00 +0000 Subject: [PATCH] Update .gitea/workflows/sonarscan.yml --- .gitea/workflows/sonarscan.yml | 54 +++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/sonarscan.yml b/.gitea/workflows/sonarscan.yml index 2fd3f17..182a797 100644 --- a/.gitea/workflows/sonarscan.yml +++ b/.gitea/workflows/sonarscan.yml @@ -1,11 +1,19 @@ -name: SonarQube Analysis +name: SonarQube Quality Gate on: push: - branches: [ testing, main ] + branches: + - testing + - main pull_request: - branches: [ testing, main ] + branches: + - testing + - main + +env: + SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }} + SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} jobs: sonarqube: @@ -22,7 +30,7 @@ jobs: with: fetch-depth: 0 - - name: Run Scan + - name: Run SonarQube Scan run: | REPO_NAME=${{ gitea.event.repository.name }} @@ -30,7 +38,39 @@ jobs: -Dsonar.projectKey=$REPO_NAME \ -Dsonar.projectName=$REPO_NAME \ -Dsonar.sources=. \ - -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \ - -Dsonar.token=${{ secrets.SONARQUBE_TOKEN }} \ + -Dsonar.host.url=$SONAR_HOST_URL \ + -Dsonar.token=$SONAR_TOKEN \ -Dsonar.exclusions=node_modules/**,dist/**,coverage/** \ - -Dsonar.qualitygate.wait=true \ No newline at end of file + -Dsonar.qualitygate.wait=true + + - name: Install jq (required for parsing) + if: gitea.event_name == 'pull_request' + run: | + apt-get update && apt-get install -y jq + + - name: Get Quality Gate Result + if: gitea.event_name == 'pull_request' + run: | + REPO_NAME=${{ gitea.event.repository.name }} + + curl -s -u $SONAR_TOKEN: \ + "$SONAR_HOST_URL/api/qualitygates/project_status?projectKey=$REPO_NAME" \ + > result.json + + STATUS=$(jq -r '.projectStatus.status' result.json) + echo "STATUS=$STATUS" >> $GITHUB_ENV + + - name: Comment on PR + if: gitea.event_name == 'pull_request' + run: | + if [ "$STATUS" = "OK" ]; then + MESSAGE=" SonarQube Quality Gate PASSED" + else + MESSAGE=" SonarQube Quality Gate FAILED" + fi + + curl -X POST \ + -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "{\"body\": \"$MESSAGE\"}" \ + ${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues/${{ gitea.event.pull_request.number }}/comments \ No newline at end of file