This commit is contained in:
@@ -37,7 +37,15 @@ jobs:
|
||||
echo "Listing files:"
|
||||
ls -la
|
||||
echo "Starting SonarQube scanner..."
|
||||
~/.sonar/scanner/dotnet-sonarscanner begin /k:"mrleo1nid_chatbot" /o:"mrleo1nid" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.coverage.exclusions="**/Migrations/**/*.cs,**/*ModelSnapshot.cs"
|
||||
~/.sonar/scanner/dotnet-sonarscanner begin \
|
||||
/k:"mrleo1nid_chatbot" \
|
||||
/o:"mrleo1nid" \
|
||||
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
|
||||
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
|
||||
/d:sonar.coverage.exclusions="**/Migrations/**,**/Migrations/*.cs,**/*ModelSnapshot.cs" \
|
||||
/d:sonar.exclusions="**/Migrations/**,**/obj/**,**/bin/**" \
|
||||
/d:sonar.sources="ChatBot/" \
|
||||
/d:sonar.tests="ChatBot.Tests/"
|
||||
echo "Building project..."
|
||||
dotnet build --verbosity normal --no-incremental
|
||||
echo "Running tests with coverage..."
|
||||
|
||||
23
.sonarqube/exclusions.txt
Normal file
23
.sonarqube/exclusions.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
# SonarQube Exclusions Reference
|
||||
# This file is for documentation only - exclusions are configured in .gitea/workflows/build.yml
|
||||
|
||||
## Coverage Exclusions (sonar.coverage.exclusions)
|
||||
**/Migrations/**
|
||||
**/Migrations/*.cs
|
||||
**/*ModelSnapshot.cs
|
||||
|
||||
## File Exclusions (sonar.exclusions)
|
||||
**/Migrations/**
|
||||
**/obj/**
|
||||
**/bin/**
|
||||
**/TestResults/**
|
||||
|
||||
## Source and Test Directories
|
||||
Sources: ChatBot/
|
||||
Tests: ChatBot.Tests/
|
||||
|
||||
## Why these exclusions?
|
||||
- Migrations: Auto-generated EF Core code
|
||||
- ModelSnapshot: Auto-generated EF Core snapshot
|
||||
- obj/bin: Build artifacts
|
||||
- TestResults: Test execution results
|
||||
@@ -53,29 +53,28 @@
|
||||
|
||||
---
|
||||
|
||||
### 2. **Создан `sonar-project.properties`**
|
||||
### 2. **Настроены исключения в `dotnet-sonarscanner begin`**
|
||||
|
||||
```properties
|
||||
# Exclude auto-generated files and migrations from analysis
|
||||
sonar.coverage.exclusions=**/Migrations/**/*.cs,**/Migrations/*.cs,**/*ModelSnapshot.cs
|
||||
sonar.exclusions=**/Migrations/**/*.cs,**/obj/**,**/bin/**
|
||||
⚠️ **Важно**: `SonarScanner for .NET` НЕ использует файл `sonar-project.properties`!
|
||||
Все настройки передаются через параметры командной строки:
|
||||
|
||||
# Exclude test projects from code coverage calculation
|
||||
sonar.test.exclusions=**/*Tests.cs,**/ChatBot.Tests/**
|
||||
|
||||
# Include only C# files
|
||||
sonar.sources=ChatBot/
|
||||
sonar.tests=ChatBot.Tests/
|
||||
|
||||
# Code coverage report paths
|
||||
sonar.cs.vscoveragexml.reportsPaths=coverage.xml
|
||||
sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
|
||||
```bash
|
||||
~/.sonar/scanner/dotnet-sonarscanner begin \
|
||||
/k:"mrleo1nid_chatbot" \
|
||||
/o:"mrleo1nid" \
|
||||
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
|
||||
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
|
||||
/d:sonar.coverage.exclusions="**/Migrations/**,**/Migrations/*.cs,**/*ModelSnapshot.cs" \
|
||||
/d:sonar.exclusions="**/Migrations/**,**/obj/**,**/bin/**" \
|
||||
/d:sonar.sources="ChatBot/" \
|
||||
/d:sonar.tests="ChatBot.Tests/"
|
||||
```
|
||||
|
||||
**Что это дает**:
|
||||
- 📊 SonarQube знает, что миграции нужно исключить
|
||||
- 📊 SonarQube знает, что миграции нужно исключить из coverage
|
||||
- 📊 Правильно определяет source и test файлы
|
||||
- 📊 Использует правильный формат coverage отчетов
|
||||
- 📊 Использует правильный формат coverage отчетов (OpenCover)
|
||||
- 📊 Исключает build артефакты (obj, bin)
|
||||
|
||||
---
|
||||
|
||||
@@ -169,14 +168,21 @@ Branch Coverage: 76.01%
|
||||
|
||||
## 🎯 Следующие шаги
|
||||
|
||||
1. **Commit и push изменений**:
|
||||
```bash
|
||||
git add .gitea/workflows/build.yml
|
||||
git add sonar-project.properties
|
||||
git add ChatBot.Tests/ChatBot.Tests.csproj
|
||||
git commit -m "Fix SonarQube coverage: exclude migrations, use coverlet"
|
||||
git push origin master
|
||||
```
|
||||
1. **Сделайте commit и push**:
|
||||
|
||||
```bash
|
||||
git add .gitea/workflows/build.yml
|
||||
git add .sonarqube/exclusions.txt
|
||||
git add ChatBot.Tests/ChatBot.Tests.csproj
|
||||
git add run-coverage-detailed.ps1
|
||||
git add SonarQube_Coverage_Fix.md
|
||||
|
||||
git commit -m "Fix SonarQube coverage: exclude migrations, use coverlet with proper exclusions"
|
||||
|
||||
git push origin master
|
||||
```
|
||||
|
||||
⚠️ **Важно**: НЕ создавайте файл `sonar-project.properties` - он не используется SonarScanner for .NET!
|
||||
|
||||
2. **Дождаться выполнения CI/CD**:
|
||||
- Проверить логи GitHub Actions/Gitea
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# SonarQube project configuration
|
||||
|
||||
# Exclude auto-generated files and migrations from analysis
|
||||
sonar.coverage.exclusions=**/Migrations/**/*.cs,**/Migrations/*.cs,**/*ModelSnapshot.cs
|
||||
sonar.exclusions=**/Migrations/**/*.cs,**/obj/**,**/bin/**
|
||||
|
||||
# Exclude test projects from code coverage calculation
|
||||
sonar.test.exclusions=**/*Tests.cs,**/ChatBot.Tests/**
|
||||
|
||||
# Include only C# files
|
||||
sonar.sources=ChatBot/
|
||||
sonar.tests=ChatBot.Tests/
|
||||
|
||||
# Code coverage report paths
|
||||
sonar.cs.vscoveragexml.reportsPaths=coverage.xml
|
||||
sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
|
||||
Reference in New Issue
Block a user