Update .gitea/workflows/qualitytest.yml

This commit is contained in:
2026-04-06 10:35:03 +00:00
parent 975341ae4c
commit ad0a17c11b

View File

@@ -23,8 +23,16 @@ jobs:
options: --user root
steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3
# ✅ Install jq (required for parsing)
- name: Install jq
run: |
apt-get update
apt-get install -y jq
# ✅ Run scan
- name: Run SonarQube Scan
run: |
REPO_NAME=${{ inputs.project_key }}
@@ -38,42 +46,54 @@ jobs:
-Dsonar.exclusions=node_modules/**,dist/**,coverage/** \
-Dsonar.qualitygate.wait=false
# wait for sonar to process results
# ✅ Wait properly (poll instead of sleep)
- 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: |
for i in {1..12}; do
RESPONSE=$(curl -s -u ${{ secrets.SONAR_TOKEN }}: \
"${{ secrets.SONAR_HOST_URL }}/api/qualitygates/project_status?projectKey=${{ inputs.project_key }}")
STATUS=$(echo $RESPONSE | grep -o '"status":"[^"]*"' | cut -d':' -f2 | tr -d '"')
STATUS=$(echo "$RESPONSE" | jq -r '.projectStatus.status // empty')
if [ ! -z "$STATUS" ] && [ "$STATUS" != "null" ]; then
echo "Sonar ready: $STATUS"
echo "STATUS=$STATUS" >> $GITHUB_ENV
exit 0
fi
echo "Waiting for Sonar... ($i)"
sleep 5
done
echo "STATUS=ERROR" >> $GITHUB_ENV
# ✅ Get summary safely
- 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 "DEBUG SUMMARY RESPONSE:"
echo "$RESPONSE"
BUGS=$(echo "$RESPONSE" | jq -r '.component.measures[] | select(.metric=="bugs") | .value // "0"')
VULN=$(echo "$RESPONSE" | jq -r '.component.measures[] | select(.metric=="vulnerabilities") | .value // "0"')
SMELLS=$(echo "$RESPONSE" | jq -r '.component.measures[] | select(.metric=="code_smells") | .value // "0"')
echo "BUGS=$BUGS" >> $GITHUB_ENV
echo "VULN=$VULN" >> $GITHUB_ENV
echo "SMELLS=$SMELLS" >> $GITHUB_ENV
# ✅ Comment on PR
- name: Comment on PR
if: gitea.event.pull_request != null
run: |
if [ "$STATUS" = "OK" ]; then
MESSAGE=" SonarQube PASSED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS"
MESSAGE=" SonarQube PASSED\n\n🐞 Bugs: $BUGS\n🔐 Vulnerabilities: $VULN\n🧹 Code Smells: $SMELLS"
else
MESSAGE=" SonarQube FAILED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS"
MESSAGE=" SonarQube FAILED\n\n🐞 Bugs: $BUGS\n🔐 Vulnerabilities: $VULN\n🧹 Code Smells: $SMELLS"
fi
curl -X POST \