|
1 | | -# This workflow uses actions that are not certified by GitHub. |
2 | | -# They are provided by a third-party and are governed by |
3 | | -# separate terms of service, privacy policy, and support |
4 | | -# documentation. |
5 | | - |
6 | | -# This workflow helps you trigger a SonarCloud analysis of your code and populates |
7 | | -# GitHub Code Scanning alerts with the vulnerabilities found. |
8 | | -# Free for open source project. |
9 | | - |
10 | | -# 1. Login to SonarCloud.io using your GitHub account |
11 | | - |
12 | | -# 2. Import your project on SonarCloud |
13 | | -# * Add your GitHub organization first, then add your repository as a new project. |
14 | | -# * Please note that many languages are eligible for automatic analysis, |
15 | | -# which means that the analysis will start automatically without the need to set up GitHub Actions. |
16 | | -# * This behavior can be changed in Administration > Analysis Method. |
17 | | -# |
18 | | -# 3. Follow the SonarCloud in-product tutorial |
19 | | -# * a. Copy/paste the Project Key and the Organization Key into the args parameter below |
20 | | -# (You'll find this information in SonarCloud. Click on "Information" at the bottom left) |
21 | | -# |
22 | | -# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN |
23 | | -# (On SonarCloud, click on your avatar on top-right > My account > Security |
24 | | -# or go directly to https://sonarcloud.io/account/security/) |
25 | | - |
26 | | -# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/) |
27 | | -# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9) |
28 | | - |
29 | | -name: SonarCloud analysis |
30 | | - |
| 1 | +name: SonarQube |
31 | 2 | on: |
32 | 3 | push: |
33 | | - branches: [ "master" ] |
| 4 | + branches: |
| 5 | + - master |
34 | 6 | pull_request: |
35 | | - branches: [ "master" ] |
36 | | - workflow_dispatch: |
37 | | - |
38 | | -permissions: |
39 | | - pull-requests: read # allows SonarCloud to decorate PRs with analysis results |
40 | | - |
| 7 | + types: [opened, synchronize, reopened] |
41 | 8 | jobs: |
42 | | - sonar-check: |
43 | | - name: Sonar Check |
44 | | - runs-on: windows-latest # безпечно для будь-яких .NET проектів |
| 9 | + build: |
| 10 | + name: Build and analyze |
| 11 | + runs-on: windows-latest |
45 | 12 | steps: |
| 13 | + - name: Set up JDK 17 |
| 14 | + uses: actions/setup-java@v4 |
| 15 | + with: |
| 16 | + java-version: 17 |
| 17 | + distribution: 'zulu' # Alternative distribution options are available. |
46 | 18 | - uses: actions/checkout@v4 |
47 | | - with: { fetch-depth: 0 } |
48 | | - |
49 | | - - uses: actions/setup-dotnet@v4 |
50 | 19 | with: |
51 | | - dotnet-version: '8.0.x' |
52 | | - |
53 | | - # 1) BEGIN: SonarScanner for .NET |
54 | | - - name: SonarScanner Begin |
| 20 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
| 21 | + - name: Cache SonarQube Cloud packages |
| 22 | + uses: actions/cache@v4 |
| 23 | + with: |
| 24 | + path: ~\sonar\cache |
| 25 | + key: ${{ runner.os }}-sonar |
| 26 | + restore-keys: ${{ runner.os }}-sonar |
| 27 | + - name: Cache SonarQube Cloud scanner |
| 28 | + id: cache-sonar-scanner |
| 29 | + uses: actions/cache@v4 |
| 30 | + with: |
| 31 | + path: ${{ runner.temp }}\scanner |
| 32 | + key: ${{ runner.os }}-sonar-scanner |
| 33 | + restore-keys: ${{ runner.os }}-sonar-scanner |
| 34 | + - name: Install SonarQube Cloud scanner |
| 35 | + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' |
| 36 | + shell: powershell |
55 | 37 | run: | |
56 | | - dotnet tool install --global dotnet-sonarscanner |
57 | | - echo "$env:USERPROFILE\.dotnet\tools" >> $env:GITHUB_PATH |
58 | | - dotnet sonarscanner begin ` |
59 | | - /k:"ppanchen_NetSdrClient" ` |
60 | | - /o:"ppanchen" ` |
61 | | - /d:sonar.token="${{ secrets.SONAR_TOKEN }}" ` |
62 | | - /d:sonar.cs.opencover.reportsPaths="**/coverage.xml" ` |
63 | | - /d:sonar.cpd.cs.minimumTokens=40 ` |
64 | | - /d:sonar.cpd.cs.minimumLines=5 ` |
65 | | - /d:sonar.exclusions=**/bin/**,**/obj/**,**/sonarcloud.yml ` |
66 | | - /d:sonar.qualitygate.wait=true |
67 | | - shell: pwsh |
68 | | - # 2) BUILD & TEST |
69 | | - - name: Restore |
70 | | - run: dotnet restore NetSdrClient.sln |
71 | | - - name: Build |
72 | | - run: dotnet build NetSdrClient.sln -c Release --no-restore |
73 | | - #coverage |
74 | | - - name: Test with coverage |
| 38 | + New-Item -Path ${{ runner.temp }}\scanner -ItemType Directory |
| 39 | + dotnet tool update dotnet-sonarscanner --tool-path ${{ runner.temp }}\scanner |
| 40 | + - name: Build and analyze |
| 41 | + env: |
| 42 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 43 | + shell: powershell |
| 44 | + run: | |
| 45 | + ${{ runner.temp }}\scanner\dotnet-sonarscanner begin /k:"Yegres546_NetSdrClient" /o:"yegres546-1" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
| 46 | + dotnet build |
| 47 | + ${{ runner.temp }}\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
| 48 | + |
| 49 | + - name: Test with coverage |
75 | 50 | run: | |
76 | 51 | dotnet test NetSdrClient.Tests/NetSdrClient.Tests.csproj -c Release \ |
77 | 52 | --logger "trx;LogFileName=test-results.trx" \ |
|
86 | 61 | name: test-coverage-results |
87 | 62 | path: NetSdrClient.Tests/TestResults/ |
88 | 63 | retention-days: 30 |
| 64 | + shell: pwsh |
89 | 65 | # 3) END: SonarScanner |
90 | 66 | - name: SonarScanner End |
91 | 67 | run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |
|
0 commit comments