This commit is contained in:
@@ -37,7 +37,15 @@ jobs:
|
|||||||
echo "Listing files:"
|
echo "Listing files:"
|
||||||
ls -la
|
ls -la
|
||||||
echo "Starting SonarQube scanner..."
|
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..."
|
echo "Building project..."
|
||||||
dotnet build --verbosity normal --no-incremental
|
dotnet build --verbosity normal --no-incremental
|
||||||
echo "Running tests with coverage..."
|
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
|
⚠️ **Важно**: `SonarScanner for .NET` НЕ использует файл `sonar-project.properties`!
|
||||||
# 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
|
```bash
|
||||||
sonar.test.exclusions=**/*Tests.cs,**/ChatBot.Tests/**
|
~/.sonar/scanner/dotnet-sonarscanner begin \
|
||||||
|
/k:"mrleo1nid_chatbot" \
|
||||||
# Include only C# files
|
/o:"mrleo1nid" \
|
||||||
sonar.sources=ChatBot/
|
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
|
||||||
sonar.tests=ChatBot.Tests/
|
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
|
||||||
|
/d:sonar.coverage.exclusions="**/Migrations/**,**/Migrations/*.cs,**/*ModelSnapshot.cs" \
|
||||||
# Code coverage report paths
|
/d:sonar.exclusions="**/Migrations/**,**/obj/**,**/bin/**" \
|
||||||
sonar.cs.vscoveragexml.reportsPaths=coverage.xml
|
/d:sonar.sources="ChatBot/" \
|
||||||
sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
|
/d:sonar.tests="ChatBot.Tests/"
|
||||||
```
|
```
|
||||||
|
|
||||||
**Что это дает**:
|
**Что это дает**:
|
||||||
- 📊 SonarQube знает, что миграции нужно исключить
|
- 📊 SonarQube знает, что миграции нужно исключить из coverage
|
||||||
- 📊 Правильно определяет source и test файлы
|
- 📊 Правильно определяет source и test файлы
|
||||||
- 📊 Использует правильный формат coverage отчетов
|
- 📊 Использует правильный формат coverage отчетов (OpenCover)
|
||||||
|
- 📊 Исключает build артефакты (obj, bin)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -169,14 +168,21 @@ Branch Coverage: 76.01%
|
|||||||
|
|
||||||
## 🎯 Следующие шаги
|
## 🎯 Следующие шаги
|
||||||
|
|
||||||
1. **Commit и push изменений**:
|
1. **Сделайте commit и push**:
|
||||||
```bash
|
|
||||||
git add .gitea/workflows/build.yml
|
```bash
|
||||||
git add sonar-project.properties
|
git add .gitea/workflows/build.yml
|
||||||
git add ChatBot.Tests/ChatBot.Tests.csproj
|
git add .sonarqube/exclusions.txt
|
||||||
git commit -m "Fix SonarQube coverage: exclude migrations, use coverlet"
|
git add ChatBot.Tests/ChatBot.Tests.csproj
|
||||||
git push origin master
|
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**:
|
2. **Дождаться выполнения CI/CD**:
|
||||||
- Проверить логи GitHub Actions/Gitea
|
- Проверить логи 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