87 lines
3.3 KiB
YAML
87 lines
3.3 KiB
YAML
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
|
|
container:
|
|
image: mcr.microsoft.com/dotnet/sdk:9.0
|
|
env:
|
|
PATH: ${{ env.PATH }}:/root/.dotnet/tools
|
|
steps:
|
|
- name: Checkout code
|
|
run: /bin/bash -c |
|
|
echo "Checking out code..."
|
|
echo "Current directory: $(pwd)"
|
|
echo "Files in current directory:"
|
|
ls -la
|
|
|
|
- name: Setup .NET
|
|
run: /bin/bash -c |
|
|
echo "Setting up .NET..."
|
|
dotnet --version
|
|
echo "Dotnet is available"
|
|
|
|
- name: Restore dependencies
|
|
run: /bin/bash -c "dotnet restore"
|
|
|
|
- name: Install dotnet-coverage
|
|
run: /bin/bash -c |
|
|
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
|
|
run: /bin/bash -c "dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner"
|
|
- name: Begin SonarCloud analysis
|
|
run: /bin/bash -c "./.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 }}
|
|
|
|
- name: Build
|
|
run: /bin/bash -c "dotnet build --no-incremental"
|
|
|
|
- name: Run tests and collect coverage
|
|
run: /bin/bash -c |
|
|
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
|
|
|
|
- name: List files for debug
|
|
run: /bin/bash -c "ls -la"
|
|
|
|
- name: Print coverage.xml for debug
|
|
run: /bin/bash -c "cat coverage.xml"
|
|
|
|
- name: End SonarCloud analysis
|
|
run: /bin/bash -c "./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token=\"${{ secrets.SONAR_TOKEN }}\""
|
|
env:
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |