Files
ChatBot/.gitea/workflows/build.yml
Leonid Pershin d9151105e8
Some checks failed
SonarQube / Build and analyze (pull_request) Failing after 2m56s
add gate
2025-10-22 03:42:41 +03:00

74 lines
3.1 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: Restore dependencies
run: dotnet restore --verbosity normal
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
echo "Starting SonarQube analysis..."
echo "Current directory: $(pwd)"
echo "Listing files:"
ls -la
echo "Starting SonarQube scanner..."
~/.sonar/scanner/dotnet-sonarscanner begin \
/k:"ChatBot" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" \
/d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" \
/d:sonar.coverage.exclusions="**/Migrations/**/*.cs,**/*ModelSnapshot.cs,**/Migrations/*.cs,**/Program.cs" \
/d:sonar.exclusions="**/Migrations/**/*.cs,**/obj/**,**/bin/**,**/TestResults/**" \
/d:sonar.cpd.exclusions="**/Migrations/**/*.cs" \
/d:sonar.test.inclusions="**/*Tests.cs,**/ChatBot.Tests/**/*.cs"
echo "Building project..."
dotnet build --verbosity normal --no-incremental
echo "Running tests with coverage..."
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./coverage/ /p:Exclude="[*]*.Migrations.*" /p:ExcludeByFile="**/Migrations/*.cs"
echo "Ending SonarQube analysis..."
~/.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Wait for Quality Gate
run: |
echo "Waiting for SonarQube Quality Gate result..."
sleep 10
# Get Quality Gate status
QUALITY_GATE_STATUS=$(curl -s -u "${{ secrets.SONAR_TOKEN }}:" \
"${{ secrets.SONAR_HOST_URL }}/api/qualitygates/project_status?projectKey=ChatBot" \
| grep -o '"status":"[^"]*"' | cut -d'"' -f4)
echo "Quality Gate Status: $QUALITY_GATE_STATUS"
if [ "$QUALITY_GATE_STATUS" != "OK" ]; then
echo "❌ Quality Gate failed! Status: $QUALITY_GATE_STATUS"
echo "Please check the SonarQube dashboard for details:"
echo "${{ secrets.SONAR_HOST_URL }}/dashboard?id=ChatBot"
exit 1
else
echo "✅ Quality Gate passed!"
fi