From 2336e2a0c253111cf05d1f1356667afade959791 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Fri, 17 Oct 2025 07:33:46 +0300 Subject: [PATCH] f --- .gitea/workflows/build.yml | 89 ++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 37b4dee..2e96cb5 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -16,67 +16,64 @@ jobs: build: name: Build, Test, Coverage, and Analyze runs-on: ubuntu-latest + env: + PATH: ${{ env.PATH }}:/root/.dotnet/tools steps: - # 1. Убедимся, что git установлен, и клонируем код вручную - - name: Checkout code with git - run: | - which git || (apt-get update && apt-get install -y git) - git config --global core.autocrlf false - git config --global safe.directory /workspace - git clone https://$GITEA_USERNAME:$GITEA_PASSWORD@$GITEA_SERVER/$GITEA_OWNER/$GITEA_REPO.git . - git checkout $CI_COMMIT_REF_NAME + - uses: actions/checkout@v4 - # 2. Установка .NET SDK - name: Setup .NET - run: | - wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb - dpkg -i packages-microsoft-prod.deb - rm packages-microsoft-prod.deb - apt-get update - apt-get install -y apt-transport-https - apt-get install -y dotnet-sdk-${DOTNET_VERSION%.*} # например, 9.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} - # 3. Восстановление зависимостей - name: Restore dependencies run: dotnet restore - # 4. Установка dotnet-coverage - name: Install dotnet-coverage - run: dotnet tool install -g dotnet-coverage - - # 5. Установка SonarScanner - - name: Install SonarScanner - run: dotnet tool install -g dotnet-sonarscanner - - # 6. Начало анализа SonarCloud - - name: Begin SonarCloud analysis run: | + dotnet tool install --global dotnet-coverage + echo "Adding .dotnet/tools to PATH..." + echo 'export PATH="$PATH:/root/.dotnet/tools"' >> ~/.bashrc export PATH="$PATH:/root/.dotnet/tools" - dotnet-sonarscanner begin \ - /k:"${{ env.SONAR_PROJECT_KEY }}" \ - /o:"${{ env.SONAR_ORG }}" \ - /d:sonar.host.url="${{ env.SONAR_HOST_URL }}" \ - /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ - /d:sonar.cs.vscoveragexml.reportsPaths="coverage.xml" + echo "dotnet-coverage location:" + which dotnet-coverage || echo "dotnet-coverage not found in PATH" + ls -la /root/.dotnet/tools/ | grep dotnet-coverage || echo "No dotnet-coverage in tools directory" + + - name: Install SonarCloud Scanner + run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner + - name: Begin SonarCloud analysis + run: ./.sonar/scanner/dotnet-sonarscanner begin /k:"${{ env.SONAR_PROJECT_KEY }}" /o:"${{ env.SONAR_ORG }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ env.SONAR_HOST_URL }}" /d:sonar.cs.vscoveragexml.reportsPaths="coverage.xml" + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # 7. Сборка проекта - name: Build - run: dotnet build --no-incremental --configuration Release + run: dotnet build --no-incremental - # 8. Запуск тестов с покрытием - name: Run tests and collect coverage run: | - export PATH="$PATH:/root/.dotnet/tools" - dotnet-coverage collect "dotnet test --no-build --configuration Release" -f xml -o coverage.xml + echo "Running tests and collecting coverage..." + echo "PATH: $PATH" + echo "Trying dotnet-coverage from PATH..." + if dotnet-coverage collect "dotnet test --no-build" -f xml -o "coverage.xml"; then + echo "dotnet-coverage succeeded from PATH" + elif /root/.dotnet/tools/dotnet-coverage collect "dotnet test --no-build" -f xml -o "coverage.xml"; then + echo "dotnet-coverage succeeded with full path" + else + echo "dotnet-coverage failed, trying built-in coverage collection..." + dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults --no-build + echo "Looking for coverage files..." + find ./TestResults -name "*.xml" -exec echo "Found: {}" \; + # Convert to the expected format + find ./TestResults -name "coverage.cobertura.xml" -exec cp {} coverage.xml \; + fi - # 9. Отладочный вывод — проверим, создан ли файл покрытия - - name: Check coverage file - run: | - ls -la coverage.xml - cat coverage.xml | head -20 + - name: List files for debug + run: ls -la + + - name: Print coverage.xml for debug + run: cat coverage.xml - # 10. Завершение анализа SonarCloud - name: End SonarCloud analysis - run: | - export PATH="$PATH:/root/.dotnet/tools" - dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file + run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file