From 49443e6ddc1c0fc34f0af5038e6dcc67e913e1e8 Mon Sep 17 00:00:00 2001 From: Rajendra Reddy Date: Mon, 6 Apr 2026 02:13:08 +0000 Subject: [PATCH] Add .gitea/workflows/qualitytest.yml --- .gitea/workflows/qualitytest.yml | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .gitea/workflows/qualitytest.yml diff --git a/.gitea/workflows/qualitytest.yml b/.gitea/workflows/qualitytest.yml new file mode 100644 index 0000000..be2c83c --- /dev/null +++ b/.gitea/workflows/qualitytest.yml @@ -0,0 +1,73 @@ +name: SonarQube Quality Gate + +on: + workflow_call: + inputs: + project_key: + required: false + type: string + secrets: + SONAR_HOST_URL: + required: true + SONAR_TOKEN: + required: true + GITEA_TOKEN: + required: true + +jobs: + sonarqube: + runs-on: ubuntu-latest + + container: + image: sonarsource/sonar-scanner-cli:12.0.0.3214_8.0.1 + options: --user root + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Run SonarQube Scan + run: | + REPO_NAME=${{ inputs.project_key || gitea.repository }} + + sonar-scanner \ + -Dsonar.projectKey=$REPO_NAME \ + -Dsonar.projectName=$REPO_NAME \ + -Dsonar.sources=. \ + -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \ + -Dsonar.token=${{ secrets.SONAR_TOKEN }} \ + -Dsonar.exclusions=node_modules/**,dist/**,coverage/** \ + -Dsonar.qualitygate.wait=false + + - name: Install jq + if: gitea.event.pull_request != null + run: | + apt-get update && apt-get install -y jq + + - name: Get Quality Gate Result + if: gitea.event.pull_request != null + run: | + REPO_NAME=${{ inputs.project_key || gitea.repository }} + + 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: Comment on PR + if: gitea.event.pull_request != null + 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