Update .gitea/workflows/qualitytest.yml
This commit is contained in:
@@ -4,7 +4,7 @@ on:
|
|||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
project_key:
|
project_key:
|
||||||
required: false
|
required: true
|
||||||
type: string
|
type: string
|
||||||
secrets:
|
secrets:
|
||||||
SONAR_HOST_URL:
|
SONAR_HOST_URL:
|
||||||
@@ -24,8 +24,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Run SonarQube Scan
|
- name: Run SonarQube Scan
|
||||||
run: |
|
run: |
|
||||||
@@ -40,30 +38,42 @@ jobs:
|
|||||||
-Dsonar.exclusions=node_modules/**,dist/**,coverage/** \
|
-Dsonar.exclusions=node_modules/**,dist/**,coverage/** \
|
||||||
-Dsonar.qualitygate.wait=false
|
-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
|
if: gitea.event.pull_request != null
|
||||||
run: |
|
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
|
STATUS=$(echo $RESPONSE | grep -o '"status":"[^"]*"' | cut -d':' -f2 | tr -d '"')
|
||||||
if: gitea.event.pull_request != null
|
|
||||||
run: |
|
|
||||||
REPO_NAME=${{ inputs.project_key }}
|
|
||||||
|
|
||||||
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
|
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
|
- name: Comment on PR
|
||||||
if: gitea.event.pull_request != null
|
if: gitea.event.pull_request != null
|
||||||
run: |
|
run: |
|
||||||
if [ "$STATUS" = "OK" ]; then
|
if [ "$STATUS" = "OK" ]; then
|
||||||
MESSAGE=" SonarQube Quality Gate PASSED"
|
MESSAGE=" SonarQube PASSED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS"
|
||||||
else
|
else
|
||||||
MESSAGE=" SonarQube Quality Gate FAILED"
|
MESSAGE=" SonarQube FAILED\n\n Bugs: $BUGS\n Vulnerabilities: $VULN\n Code Smells: $SMELLS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
|
|||||||
Reference in New Issue
Block a user