Add .gitea/workflows/qualitytest.yml

This commit is contained in:
2026-04-06 02:13:08 +00:00
parent e824e4f2a4
commit 49443e6ddc

View File

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