Files
VectorDBDemo/.gitea/workflows/sonar-scan.yml
ShaoHua 8544f013d0
Some checks failed
SonarQube Code Quality Scan / scan (push) Failing after 3s
fix workflow: remove github dependency + duplicate scan
2025-12-05 16:08:25 +08:00

91 lines
3.1 KiB
YAML

name: SonarQube Code Quality Scan
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
scan:
runs-on: windows-latest
env:
PROXY_HOST: 127.0.0.1
PROXY_PORT: 7890
# 升级到 11.0.0 版本(适配 SAFETY 枚举值)
DC_VERSION: 11.0.0
DC_OUTPUT: ./depcheck
steps:
- name: Checkout Code (Gitea Direct)
run: |
git clone https://git.we965.cn/learning/VectorDBDemo.git .
git fetch --depth=0
git checkout ${{ github.ref_name }}
shell: pwsh
- name: Add Sonar Scanner to PATH
run: |
echo "D:\Paths\sonar-scanner-cli\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
shell: pwsh
- name: Verify .NET SDK (Local)
run: |
dotnet --list-sdks
dotnet --version
shell: pwsh
- name: Run OWASP Dependency Check
run: |
New-Item -Path $env:DC_OUTPUT -ItemType Directory -Force
# 修正:移除参数前的空格,避免 PowerShell 语法错误
dependency-check.bat `
--project "VectorDBDemo" `
--scan "." `
--format "XML" `
--out $env:DC_OUTPUT `
-Dproxy.host=$env:PROXY_HOST `
-Dproxy.port=$env:PROXY_PORT `
-DconnectionTimeout=30000 `
-DreadTimeout=30000
shell: pwsh
continue-on-error: false
- name: Build .NET Project
run: |
dotnet restore
dotnet build --configuration Release --no-restore
shell: pwsh
- name: SonarQube Full Scan
run: |
dotnet tool install --global dotnet-sonarscanner --no-cache
dotnet sonarscanner begin `
/k:"vectordbdemo" `
/d:sonar.host.url="http://127.0.0.1:9000" `
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" `
/d:sonar.sources="./" `
/d:sonar.exclusions="**/obj/**,**/bin/**,dc/**,depcheck/**" `
/d:sonar.dependencyCheck.xmlReportPath="${env:DC_OUTPUT}/dependency-check-report.xml" `
/d:sonar.verbose=true
dotnet build --configuration Release --no-restore
dotnet sonarscanner end `
/d:sonar.login="${{ secrets.SONAR_TOKEN }}"
shell: pwsh
- name: Fetch SonarQube Blocker Issues
id: fetch_issues
run: |
$projectKey = "vectordbdemo"
$sonarApiUrl = "http://127.0.0.1:9000/api/issues/search?projectKeys=$projectKey&severities=BLOCKER&statuses=OPEN"
$response = Invoke-RestMethod -Uri $sonarApiUrl -Headers @{
"Authorization" = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${{ secrets.SONAR_TOKEN }}:")))"
} -Method Get
$blockerCount = $response.total
echo "blocker_issues_count=$blockerCount" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8
if ($blockerCount -gt 0) {
Write-Error "Found $blockerCount Blocker issues in SonarQube"
exit 1
}
shell: pwsh