From 975341ae4c4547f1aec7d1c7b1e1e1eb6660798b Mon Sep 17 00:00:00 2001 From: Rajendra Reddy Date: Mon, 6 Apr 2026 07:51:42 +0000 Subject: [PATCH] Update .gitea/workflows/qualitytest.yml --- .gitea/workflows/qualitytest.yml | 42 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.gitea/workflows/qualitytest.yml b/.gitea/workflows/qualitytest.yml index a9a80aa..d1eec51 100644 --- a/.gitea/workflows/qualitytest.yml +++ b/.gitea/workflows/qualitytest.yml @@ -4,7 +4,7 @@ on: workflow_call: inputs: project_key: - required: false + required: true type: string secrets: SONAR_HOST_URL: @@ -24,8 +24,6 @@ jobs: steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: Run SonarQube Scan run: | @@ -40,30 +38,42 @@ jobs: -Dsonar.exclusions=node_modules/**,dist/**,coverage/** \ -Dsonar.qualitygate.wait=false - - name: Install jq + # wait for sonar to process results + - name: Wait for Sonar processing + if: gitea.event.pull_request != null + run: sleep 10 + + - name: Get Quality Gate if: gitea.event.pull_request != null run: | - apt update && apt install jq -y + RESPONSE=$(curl -s -u ${{ secrets.SONAR_TOKEN }}: \ + "${{ secrets.SONAR_HOST_URL }}/api/qualitygates/project_status?projectKey=${{ inputs.project_key }}") - - name: Get Quality Gate Result - if: gitea.event.pull_request != null - run: | - REPO_NAME=${{ inputs.project_key }} + STATUS=$(echo $RESPONSE | grep -o '"status":"[^"]*"' | cut -d':' -f2 | tr -d '"') - curl -s -u ${{ secrets.SONAR_TOKEN }}: \ - "${{ secrets.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: Get Sonar Summary + if: gitea.event.pull_request != null + run: | + RESPONSE=$(curl -s -u ${{ secrets.SONAR_TOKEN }}: \ + "${{ secrets.SONAR_HOST_URL }}/api/measures/component?component=${{ inputs.project_key }}&metricKeys=bugs,vulnerabilities,code_smells") + + BUGS=$(echo $RESPONSE | grep -o '"metric":"bugs","value":"[^"]*"' | cut -d'"' -f6) + VULN=$(echo $RESPONSE | grep -o '"metric":"vulnerabilities","value":"[^"]*"' | cut -d'"' -f6) + SMELLS=$(echo $RESPONSE | grep -o '"metric":"code_smells","value":"[^"]*"' | cut -d'"' -f6) + + echo "BUGS=$BUGS" >> $GITHUB_ENV + echo "VULN=$VULN" >> $GITHUB_ENV + echo "SMELLS=$SMELLS" >> $GITHUB_ENV + - name: Comment on PR if: gitea.event.pull_request != null run: | if [ "$STATUS" = "OK" ]; then - MESSAGE=" SonarQube Quality Gate PASSED" + MESSAGE=" SonarQube PASSED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS" else - MESSAGE=" SonarQube Quality Gate FAILED" + MESSAGE=" SonarQube FAILED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS" fi curl -X POST \