This commit is contained in:
Leonid Pershin
2025-10-17 07:31:25 +03:00
parent 9af38f22ad
commit d0da72cc10

View File

@@ -16,64 +16,67 @@ jobs:
build: build:
name: Build, Test, Coverage, and Analyze name: Build, Test, Coverage, and Analyze
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
PATH: ${{ env.PATH }}:/root/.dotnet/tools
steps: 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 - name: Setup .NET
uses: actions/setup-dotnet@v4 run: |
with: wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dotnet-version: ${{ env.DOTNET_VERSION }} 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 - name: Restore dependencies
run: dotnet restore run: dotnet restore
# 4. Установка dotnet-coverage
- name: Install dotnet-coverage - name: Install dotnet-coverage
run: | run: dotnet tool install -g dotnet-coverage
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"
- name: Install SonarCloud Scanner # 5. Установка SonarScanner
run: dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner - name: Install SonarScanner
run: dotnet tool install -g dotnet-sonarscanner
# 6. Начало анализа SonarCloud
- name: Begin SonarCloud analysis - 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" run: |
env: export PATH="$PATH:/root/.dotnet/tools"
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 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 - name: Build
run: dotnet build --no-incremental run: dotnet build --no-incremental --configuration Release
# 8. Запуск тестов с покрытием
- name: Run tests and collect coverage - name: Run tests and collect coverage
run: | run: |
echo "Running tests and collecting coverage..." export PATH="$PATH:/root/.dotnet/tools"
echo "PATH: $PATH" dotnet-coverage collect "dotnet test --no-build --configuration Release" -f xml -o coverage.xml
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
- name: List files for debug # 9. Отладочный вывод — проверим, создан ли файл покрытия
run: ls -la - name: Check coverage file
run: |
- name: Print coverage.xml for debug ls -la coverage.xml
run: cat coverage.xml cat coverage.xml | head -20
# 10. Завершение анализа SonarCloud
- name: End SonarCloud analysis - name: End SonarCloud analysis
run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" run: |
env: export PATH="$PATH:/root/.dotnet/tools"
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"