diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 2e96cb5..37b4dee 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -16,64 +16,67 @@ jobs: build: name: Build, Test, Coverage, and Analyze runs-on: ubuntu-latest - env: - PATH: ${{ env.PATH }}:/root/.dotnet/tools steps: - - uses: actions/checkout@v4 + # 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 + # 2. Установка .NET SDK - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} + 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 + # 3. Восстановление зависимостей - name: Restore dependencies run: dotnet restore + # 4. Установка dotnet-coverage - name: Install dotnet-coverage - 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" - 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" + run: dotnet tool install -g dotnet-coverage - - name: Install SonarCloud Scanner - run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner + # 5. Установка SonarScanner + - name: Install SonarScanner + run: dotnet tool install -g dotnet-sonarscanner + + # 6. Начало анализа SonarCloud - 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 }} + run: | + 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" + # 7. Сборка проекта - name: Build - run: dotnet build --no-incremental + run: dotnet build --no-incremental --configuration Release + # 8. Запуск тестов с покрытием - name: Run tests and collect coverage run: | - 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 + export PATH="$PATH:/root/.dotnet/tools" + dotnet-coverage collect "dotnet test --no-build --configuration Release" -f xml -o coverage.xml - - name: List files for debug - run: ls -la - - - name: Print coverage.xml for debug - run: cat coverage.xml + # 9. Отладочный вывод — проверим, создан ли файл покрытия + - name: Check coverage file + run: | + ls -la coverage.xml + cat coverage.xml | head -20 + # 10. Завершение анализа SonarCloud - name: End SonarCloud analysis - run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + run: | + export PATH="$PATH:/root/.dotnet/tools" + dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file