This commit is contained in:
Leonid Pershin
2025-10-17 07:19:38 +03:00
parent bb5f4250c2
commit 9f54eb0814

View File

@@ -1,94 +1,55 @@
name: SonarQube name: SonarCloud
on: on:
push: push:
branches: branches: [ master ]
- master
pull_request: pull_request:
types: [opened, synchronize, reopened] 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: jobs:
build: build:
name: Build 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:
- name: Checkout code - uses: actions/checkout@v4
run: |
echo "Checking out code..."
echo "Current directory: $(pwd)"
echo "Files in current directory:"
ls -la
- name: Setup .NET - name: Setup .NET
run: | uses: actions/setup-dotnet@v4
echo "Setting up .NET..." with:
dotnet --version dotnet-version: ${{ env.DOTNET_VERSION }}
echo "Dotnet is available"
- name: Install SonarQube Cloud scanner
run: |
mkdir -p ~/.sonar/scanner
dotnet tool install dotnet-sonarscanner --tool-path ~/.sonar/scanner
- name: Install coverlet.collector
run: |
dotnet tool install --global coverlet.console
echo "Adding .dotnet/tools to PATH..."
export PATH="$PATH:/root/.dotnet/tools"
echo "Coverlet installed at:"
which coverlet || echo "Coverlet not found, trying full path..."
ls -la /root/.dotnet/tools/ | grep coverlet || echo "No coverlet in tools directory"
- name: Restore dependencies - name: Restore dependencies
run: dotnet restore --verbosity normal run: dotnet restore
- name: SonarQube begin
- name: Install dotnet-coverage
run: dotnet tool install --global dotnet-coverage
- 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: env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
echo "Starting SonarQube analysis..."
echo "Current directory: $(pwd)"
echo "Listing files:"
ls -la
echo "Installing SonarQube scanner..."
if [ -n "$SONAR_TOKEN" ]; then
~/.sonar/scanner/dotnet-sonarscanner begin /k:"mrleo1nid_chatbot" /o:"mrleo1nid" /d:sonar.token="$SONAR_TOKEN" /d:sonar.cs.opencover.reportsPaths=coverage.xml /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
echo "SonarQube analysis started"
else
echo "SONAR_TOKEN not set, skipping SonarQube analysis"
fi
- name: Build project - name: Build
run: | run: dotnet build --no-incremental
echo "Building project..."
dotnet build --verbosity normal
- name: Run tests with coverage - name: Run tests and collect coverage
run: | run: dotnet-coverage collect "dotnet test --no-build" -f xml -o "coverage.xml"
echo "Running tests with coverage..."
echo "Current directory: $(pwd)"
echo "PATH: $PATH"
echo "Coverlet location:"
which coverlet || echo "Coverlet not found in PATH"
echo "Checking test project structure..."
find . -name "*.Tests.dll" -type f | head -5
echo "Trying to run coverlet..."
if coverlet ./ChatBot.Tests/bin/Debug/net9.0/ChatBot.Tests.dll --target "dotnet" --targetargs "test --no-build" -f=opencover -o="coverage.xml"; then
echo "Coverlet succeeded"
elif /root/.dotnet/tools/coverlet ./ChatBot.Tests/bin/Debug/net9.0/ChatBot.Tests.dll --target "dotnet" --targetargs "test --no-build" -f=opencover -o="coverage.xml"; then
echo "Coverlet succeeded with full path"
else
echo "Coverlet failed, trying built-in coverage collection..."
dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults
echo "Looking for coverage files..."
find ./TestResults -name "*.xml" -exec echo "Found: {}" \;
# Convert to OpenCover format if needed
find ./TestResults -name "coverage.cobertura.xml" -exec cp {} coverage.xml \;
fi
- name: SonarQube end - name: List files for debug
run: ls -la
- name: Print coverage.xml for debug
run: cat coverage.xml
- name: End SonarCloud analysis
run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
env: env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
echo "Ending SonarQube analysis..."
if [ -n "$SONAR_TOKEN" ]; then
~/.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="$SONAR_TOKEN"
echo "SonarQube analysis completed"
else
echo "SONAR_TOKEN not set, skipping SonarQube analysis"
fi