From 800a3e97ebc0f77d78623521c45943a7a188c28b Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Tue, 21 Oct 2025 03:50:42 +0300 Subject: [PATCH] fix --- .gitea/workflows/build.yml | 10 ++++++- .sonarqube/exclusions.txt | 23 ++++++++++++++++ SonarQube_Coverage_Fix.md | 56 +++++++++++++++++++++----------------- sonar-project.properties | 16 ----------- 4 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 .sonarqube/exclusions.txt delete mode 100644 sonar-project.properties diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 0088321..a3aad8d 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -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..." diff --git a/.sonarqube/exclusions.txt b/.sonarqube/exclusions.txt new file mode 100644 index 0000000..90438eb --- /dev/null +++ b/.sonarqube/exclusions.txt @@ -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 diff --git a/SonarQube_Coverage_Fix.md b/SonarQube_Coverage_Fix.md index 15e4803..bddf9e5 100644 --- a/SonarQube_Coverage_Fix.md +++ b/SonarQube_Coverage_Fix.md @@ -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 diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 3fb431a..0000000 --- a/sonar-project.properties +++ /dev/null @@ -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