Files
ChatBot/.gitea/workflows/build.yml
Leonid Pershin d0da72cc10 f
2025-10-17 07:31:25 +03:00

82 lines
2.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: SonarCloud
on:
push:
branches: [ master ]
pull_request:
types: [opened, synchronize, reopened]
env:
DOTNET_VERSION: '9.0.x'
SONAR_PROJECT_KEY: 'mrleo1nid_chatbot'
SONAR_ORG: 'mrleo1nid'
SONAR_HOST_URL: 'https://sonarcloud.io'
jobs:
build:
name: Build, Test, Coverage, and Analyze
runs-on: ubuntu-latest
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
# 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
# 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: |
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 --configuration Release
# 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
# 9. Отладочный вывод — проверим, создан ли файл покрытия
- name: Check coverage file
run: |
ls -la coverage.xml
cat coverage.xml | head -20
# 10. Завершение анализа SonarCloud
- name: End SonarCloud analysis
run: |
export PATH="$PATH:/root/.dotnet/tools"
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"