Skip to content

Commit 9634a73

Browse files
Update SonarCloud workflow (#34)
* Update SonarCloud workflow * SonarCloud * Potential fix for code scanning alert no. 1: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 03edf01 commit 9634a73

1 file changed

Lines changed: 36 additions & 42 deletions

File tree

.github/workflows/sonarcloud.yml

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
11
name: SonarCloud
2-
2+
permissions:
3+
contents: read
34
on:
45
push:
5-
branches: [ "main" ]
6+
branches:
7+
- main
68
pull_request:
7-
branches: [ "main" ]
8-
workflow_dispatch:
9-
9+
types: [opened, synchronize, reopened]
1010
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
1714
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.
1820
- uses: actions/checkout@v4
1921
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
2432
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
2839
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
3643
env:
3744
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45+
shell: powershell
3846
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

Comments
 (0)