|
1 | 1 | name: SonarCloud |
2 | | - |
| 2 | +permissions: |
| 3 | + contents: read |
3 | 4 | on: |
4 | 5 | push: |
5 | | - branches: [ "main" ] |
| 6 | + branches: |
| 7 | + - main |
6 | 8 | pull_request: |
7 | | - branches: [ "main" ] |
8 | | - workflow_dispatch: |
9 | | - |
| 9 | + types: [opened, synchronize, reopened] |
10 | 10 | jobs: |
11 | | - sonarcloud: |
12 | | - runs-on: ubuntu-latest |
13 | | - permissions: |
14 | | - contents: read |
15 | | - id-token: write |
16 | | - |
| 11 | + build: |
| 12 | + name: Build and analyze |
| 13 | + runs-on: windows-latest |
17 | 14 | steps: |
| 15 | + - name: Set up JDK 17 |
| 16 | + uses: actions/setup-java@v4 |
| 17 | + with: |
| 18 | + java-version: 17 |
| 19 | + distribution: 'zulu' # Alternative distribution options are available. |
18 | 20 | - uses: actions/checkout@v4 |
19 | 21 | with: |
20 | | - fetch-depth: 0 |
21 | | - |
22 | | - - name: Setup .NET |
23 | | - uses: actions/setup-dotnet@v4 |
| 22 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 23 | + - name: Cache SonarQube Cloud packages |
| 24 | + uses: actions/cache@v4 |
| 25 | + with: |
| 26 | + path: ~\sonar\cache |
| 27 | + key: ${{ runner.os }}-sonar |
| 28 | + restore-keys: ${{ runner.os }}-sonar |
| 29 | + - name: Cache SonarQube Cloud scanner |
| 30 | + id: cache-sonar-scanner |
| 31 | + uses: actions/cache@v4 |
24 | 32 | with: |
25 | | - dotnet-version: 10.0.x |
26 | | - |
27 | | - - name: Install SonarScanner for .NET |
| 33 | + path: ${{ runner.temp }}\scanner |
| 34 | + key: ${{ runner.os }}-sonar-scanner |
| 35 | + restore-keys: ${{ runner.os }}-sonar-scanner |
| 36 | + - name: Install SonarQube Cloud scanner |
| 37 | + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' |
| 38 | + shell: powershell |
28 | 39 | run: | |
29 | | - dotnet tool install --global dotnet-sonarscanner |
30 | | - dotnet tool install --global dotnet-coverage |
31 | | -
|
32 | | - - name: Restore dependencies |
33 | | - run: dotnet restore SLNX-validator.slnx |
34 | | - |
35 | | - - name: Begin SonarCloud analysis |
| 40 | + New-Item -Path ${{ runner.temp }}\scanner -ItemType Directory |
| 41 | + dotnet tool update dotnet-sonarscanner --tool-path ${{ runner.temp }}\scanner |
| 42 | + - name: Build and analyze |
36 | 43 | env: |
37 | 44 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 45 | + shell: powershell |
38 | 46 | run: | |
39 | | - dotnet sonarscanner begin \ |
40 | | - /k:"slnx-validator" \ |
41 | | - /o:"304notmodified" \ |
42 | | - /d:sonar.token="${SONAR_TOKEN}" \ |
43 | | - /d:sonar.host.url="https://sonarcloud.io" \ |
44 | | - /d:sonar.cs.vscoveragexml.reportsPaths="coverage.xml" |
45 | | -
|
46 | | - - name: Build |
47 | | - run: dotnet build SLNX-validator.slnx --no-incremental -c Release |
48 | | - |
49 | | - - name: Test with coverage |
50 | | - run: dotnet-coverage collect "dotnet test --solution SLNX-validator.slnx --no-build -c Release --verbosity normal" -f xml -o coverage.xml |
51 | | - |
52 | | - - name: End SonarCloud analysis |
53 | | - env: |
54 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
55 | | - run: dotnet sonarscanner end /d:sonar.token="${SONAR_TOKEN}" |
| 47 | + ${{ runner.temp }}\scanner\dotnet-sonarscanner begin /k:"slnx-validator" /o:"304notmodified" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
| 48 | + dotnet build |
| 49 | + ${{ runner.temp }}\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
0 commit comments