Skip to content

Commit

Permalink
Update sonar-cloud.yml (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibranco authored Jul 18, 2024
1 parent a89c296 commit 7d10a5d
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions .github/workflows/sonar-cloud.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
name: Sonar Cloud Analysis
name: Sonar Cloud

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
runs-on: ubuntu-latest
SonarCloudAnalysis:
name: Sonar Cloud Analysis
runs-on: windows-latest
steps:

- name: Set up JDK 11
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

- name: Checkout code
uses: actions/checkout@v4
java-version: 21

- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner

- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Install dependencies
run: dotnet restore

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" /o:"${{ vars.SONAR_ORG }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build
dotnet test --collect:"XPlat Code Coverage"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
.\.sonar\scanner\dotnet-sonarscanner begin /k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" /o:"${{ github.repository_owner }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build -c Release --verbosity minimal
dotnet test -c Release --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

0 comments on commit 7d10a5d

Please sign in to comment.