Update README.md #126
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "SonarCloud - DevSecOpsUC (.NET)" | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| types: [ opened, synchronize, reopened ] | |
| jobs: | |
| sonarcloud: | |
| runs-on: ubuntu-latest | |
| name: SonarCloud Analysis (.NET 8 + KeyVault) | |
| steps: | |
| # --- 1️⃣ Checkout --- | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # --- 2️⃣ Azure Login --- | |
| - name: 🔑 Azure Login | |
| uses: azure/login@v2 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| # --- 3️⃣ Obtener secretos desde KeyVault --- | |
| - name: 🔐 Load SonarCloud secrets | |
| id: get-sonar | |
| run: | | |
| TOKEN=$(az keyvault secret show --name "SONAR-TOKEN" --vault-name "kv-devsecopsuc" --query value -o tsv) | |
| PROJECT_KEY=$(az keyvault secret show --name "SONAR-PROJECT-KEY" --vault-name "kv-devsecopsuc" --query value -o tsv) | |
| ORG=$(az keyvault secret show --name "SONAR-ORGANIZATION" --vault-name "kv-devsecopsuc" --query value -o tsv) | |
| echo "token=$TOKEN" >> $GITHUB_OUTPUT | |
| echo "project_key=$PROJECT_KEY" >> $GITHUB_OUTPUT | |
| echo "org=$ORG" >> $GITHUB_OUTPUT | |
| # --- 4️⃣ Entornos --- | |
| - name: ⚙️ Setup .NET y Java | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'zulu' | |
| java-version: 17 | |
| # --- 5️⃣ Instalar SonarScanner --- | |
| - name: 🧰 Install SonarScanner | |
| run: | | |
| dotnet tool install --global dotnet-sonarscanner --version 5.* | |
| echo "PATH=$PATH:/home/runner/.dotnet/tools" >> $GITHUB_ENV | |
| # --- 6️⃣ Begin SonarCloud analysis --- | |
| - name: ☁️ Begin SonarCloud analysis | |
| working-directory: Unidad1_AsegurandoCodigoFuente | |
| env: | |
| SONAR_TOKEN: ${{ steps.get-sonar.outputs.token }} | |
| SONAR_PROJECT_KEY: ${{ steps.get-sonar.outputs.project_key }} | |
| SONAR_ORGANIZATION: ${{ steps.get-sonar.outputs.org }} | |
| run: | | |
| dotnet sonarscanner begin \ | |
| /k:"$SONAR_PROJECT_KEY" \ | |
| /o:"$SONAR_ORGANIZATION" \ | |
| /d:sonar.token="$SONAR_TOKEN" \ | |
| /d:sonar.host.url="https://sonarcloud.io" \ | |
| /d:sonar.scm.provider=git \ | |
| /d:sonar.cs.cobertura.reportsPaths="TestResults/Coverage/*.cobertura.xml" \ | |
| /d:sonar.coverage.exclusions="**/Program.cs,**/Program.Partial.cs,**/bin/**,**/obj/**,**/TestResults/**" \ | |
| /d:sonar.exclusions="**/bin/**,**/obj/**,**/*.yml,**/node_modules/**,**/Dockerfile" | |
| # --- 7️⃣ Build solution --- | |
| - name: 🏗️ Build solution | |
| working-directory: Unidad1_AsegurandoCodigoFuente | |
| run: | | |
| dotnet restore AsegurandoCodigo.sln | |
| dotnet build AsegurandoCodigo.sln --configuration Release --no-restore | |
| # --- 8️⃣ Ejecutar tests con cobertura (ruta fija) --- | |
| - name: 🧪 Run Unit Tests with Coverage | |
| working-directory: Unidad1_AsegurandoCodigoFuente | |
| run: | | |
| mkdir -p TestResults/Coverage | |
| dotnet test auth-service.Tests/auth-service.Tests.csproj \ | |
| --configuration Release --no-build \ | |
| /p:CollectCoverage=true \ | |
| /p:CoverletOutputFormat=cobertura \ | |
| /p:CoverletOutput=TestResults/Coverage/auth-coverage.cobertura.xml | |
| dotnet test rooms-service.Tests/rooms-service.Tests.csproj \ | |
| --configuration Release --no-build \ | |
| /p:CollectCoverage=true \ | |
| /p:CoverletOutputFormat=cobertura \ | |
| /p:CoverletOutput=TestResults/Coverage/rooms-coverage.cobertura.xml | |
| echo "📁 Archivos de cobertura generados:" | |
| find TestResults/Coverage -name "*.xml" | |
| # --- 9️⃣ End analysis --- | |
| - name: 🧾 End SonarCloud analysis | |
| working-directory: Unidad1_AsegurandoCodigoFuente | |
| env: | |
| SONAR_TOKEN: ${{ steps.get-sonar.outputs.token }} | |
| run: dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN" |