Update .gitea/workflows/qualitytest.yml

This commit is contained in:
2026-04-06 07:51:42 +00:00
parent ecca3dfd32
commit 975341ae4c

View File

@@ -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 \