|
| 1 | +name: SonarCloud |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened] |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + name: Build and analyze |
| 13 | + runs-on: windows-latest |
| 14 | + steps: |
| 15 | + - name: Set up JDK 17 |
| 16 | + uses: actions/setup-java@v3 |
| 17 | + with: |
| 18 | + java-version: 17 |
| 19 | + distribution: 'zulu' # Alternative distribution options are available. |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 23 | + - name: Cache SonarCloud packages |
| 24 | + uses: actions/cache@v3 |
| 25 | + with: |
| 26 | + path: ~\sonar\cache |
| 27 | + key: ${{ runner.os }}-sonar |
| 28 | + restore-keys: ${{ runner.os }}-sonar |
| 29 | + - name: Cache SonarCloud scanner |
| 30 | + id: cache-sonar-scanner |
| 31 | + uses: actions/cache@v3 |
| 32 | + with: |
| 33 | + path: .\.sonar\scanner |
| 34 | + key: ${{ runner.os }}-sonar-scanner |
| 35 | + restore-keys: ${{ runner.os }}-sonar-scanner |
| 36 | + - name: Install SonarCloud scanner |
| 37 | + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' |
| 38 | + shell: powershell |
| 39 | + run: | |
| 40 | + New-Item -Path .\.sonar\scanner -ItemType Directory |
| 41 | + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner |
| 42 | + - name: Build and analyze |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 45 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 46 | + shell: powershell |
| 47 | + run: | |
| 48 | + .\.sonar\scanner\dotnet-sonarscanner begin /k:"sir-gon_algorithm-exercises-csharp" /o:"sir-gon" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" |
| 49 | + dotnet restore |
| 50 | + dotnet build --no-restore |
| 51 | + dotnet test --no-build --verbosity normal |
| 52 | + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
0 commit comments