75 lines
2.8 KiB
YAML
75 lines
2.8 KiB
YAML
name: SonarQube
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
jobs:
|
|
build:
|
|
name: Build and analyze
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
java-version: 17
|
|
distribution: 'zulu' # Alternative distribution options are available.
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '9.0.x'
|
|
- 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 "Coverlet installed at:"
|
|
which coverlet
|
|
- name: Restore dependencies
|
|
run: dotnet restore --verbosity normal
|
|
- name: SonarQube begin
|
|
env:
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
run: |
|
|
echo "Starting SonarQube analysis..."
|
|
echo "Current directory: $(pwd)"
|
|
echo "Listing files:"
|
|
ls -la
|
|
echo "Installing SonarQube scanner..."
|
|
~/.sonar/scanner/dotnet-sonarscanner begin /k:"mrleo1nid_chatbot" /o:"mrleo1nid" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.opencover.reportsPaths=coverage.xml /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
|
|
|
|
- name: Build project
|
|
run: |
|
|
echo "Building project..."
|
|
dotnet build --verbosity normal
|
|
|
|
- name: Run tests with coverage
|
|
run: |
|
|
echo "Running tests with coverage..."
|
|
echo "PATH: $PATH"
|
|
echo "Coverlet location:"
|
|
which coverlet || echo "Coverlet not found in PATH"
|
|
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"
|
|
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
|
|
env:
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
run: |
|
|
echo "Ending SonarQube analysis..."
|
|
~/.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |