Skip to content

Commit 266c024

Browse files
committed
feat: enhance GitHub Actions workflow for MacOS with SonarCloud integration and caching
1 parent e0380dc commit 266c024

1 file changed

Lines changed: 41 additions & 14 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,44 @@ jobs:
3131
uses: actions/setup-dotnet@v4
3232
with:
3333
dotnet-version: ${{ matrix.dotnet.version }}
34+
35+
- name: Setup Java
36+
if: matrix.platform.name == 'MacOS'
37+
uses: actions/setup-java@v4
38+
with:
39+
distribution: 'zulu'
40+
java-version: '21'
41+
42+
- name: Cache SonarCloud packages
43+
if: matrix.platform.name == 'MacOS'
44+
uses: actions/cache@v4
45+
with:
46+
path: ~/sonar/cache
47+
key: ${{ runner.os }}-sonar
48+
restore-keys: ${{ runner.os }}-sonar
49+
50+
- name: Cache SonarCloud scanner
51+
if: matrix.platform.name == 'MacOS'
52+
id: cache-sonar-scanner
53+
uses: actions/cache@v4
54+
with:
55+
path: ./.sonar/scanner
56+
key: ${{ runner.os }}-sonar-scanner
57+
restore-keys: ${{ runner.os }}-sonar-scanner
58+
59+
- name: Install SonarCloud scanner
60+
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' && matrix.platform.name == 'MacOS'
61+
shell: pwsh
62+
run: |
63+
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
64+
3465
- name: Enforce SDK Version
3566
run: dotnet new globaljson --sdk-version ${{ steps.setup-dotnet.outputs.dotnet-version }} --force
67+
68+
- name: pre_build
69+
if: matrix.platform.name == 'MacOS'
70+
run: ./.sonar/scanner/dotnet-sonarscanner begin /k:"magic5644_codeLineCounter" /o:"magic5644" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
71+
3672
- name: Build
3773
run: dotnet build -c Release
3874
- name: Test
@@ -44,6 +80,10 @@ jobs:
4480
dotnet tool install --global dotnet-reportgenerator-globaltool
4581
reportgenerator -reports:test-result.cobertura.xml -targetdir:coverage-report -reporttypes:"Html;JsonSummary;MarkdownSummaryGithub;Badges"
4682
cat coverage-report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
83+
84+
- name: post_build
85+
if: matrix.platform.name == 'MacOS'
86+
run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
4787

4888
- name: ReportGenerator
4989
if: matrix.platform.name == 'MacOS'
@@ -85,20 +125,7 @@ jobs:
85125
echo "![Coverage](./coverage-report/badge_combined.svg)" > coverage-badge.md
86126
cat coverage-badge.md >> README.md
87127
88-
sonarcloud:
89-
name: SonarCloud
90-
runs-on: ubuntu-24.04
91-
needs: build
92-
steps:
93-
- uses: actions/checkout@v4
94-
with:
95-
# Disabling shallow clone is recommended for improving relevancy of reporting
96-
fetch-depth: 0
97-
- name: SonarCloud Scan
98-
uses: SonarSource/sonarcloud-github-action@v2
99-
env:
100-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
128+
102129

103130
publish_badge:
104131
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)