1- name : " CI & CD: Build & Test .NET Solution, Create & Validate & Publish Nuget Package and Create Release"
1+ name : " CI & CD: Build & Test & Lint .NET Solution, Create & Validate & Publish Nuget Package and Create Release"
22
33on :
44 push :
1717 NuGetVersion : 0.0.0
1818
1919jobs :
20- build_test :
20+ job_build_test :
2121 name : Build & Test
2222 runs-on : ubuntu-latest
2323 steps :
@@ -26,15 +26,41 @@ jobs:
2626 - name : Setup .NET
2727 uses : actions/setup-dotnet@v4
2828 with :
29- dotnet-version : " 8 "
29+ global-json-file : " ./global.json "
3030
3131 - name : Build solution
3232 run : dotnet build
3333
3434 - name : Test solution
35- run : dotnet test --no-build
35+ run : dotnet test --no-build --logger GitHubActions
36+ # Logger: https://github.com/Tyrrrz/GitHubActionsTestLogger
3637
37- analyze_codeql :
38+ - name : Verify results
39+ if : failure()
40+ uses : actions/upload-artifact@v4
41+ with :
42+ name : verify-test-results
43+ path : |
44+ **/*.received.*
45+
46+ job_lint :
47+ name : Lint
48+ runs-on : ubuntu-latest
49+ steps :
50+ - uses : actions/checkout@v4
51+
52+ - name : Setup .NET
53+ uses : actions/setup-dotnet@v4
54+ with :
55+ global-json-file : " ./global.json"
56+
57+ - name : Restore .NET tools
58+ run : dotnet tool restore
59+
60+ - name : Linting
61+ run : dotnet csharpier --check .
62+
63+ job_analyze_codeql :
3864 name : Run CodeQL scanning
3965 runs-on : ubuntu-latest
4066 permissions :
5581 - name : Perform CodeQL Analysis
5682 uses : github/codeql-action/analyze@v3
5783
58- analyze_sonarcloud :
84+ job_analyze_sonarcloud :
5985 name : Run SonarCloud scanning
6086 runs-on : windows-latest
6187 steps :
6692 - name : Setup .NET
6793 uses : actions/setup-dotnet@v4
6894 with :
69- dotnet-version : " 8"
95+ global-json-file : " ./global.json"
96+
97+ - name : Install dotnet-coverage
98+ run : dotnet tool install dotnet-coverage --global
7099
71100 - name : Cache SonarCloud packages
72101 uses : actions/cache@v4
@@ -96,16 +125,21 @@ jobs:
96125 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
97126 shell : powershell
98127 run : |
99- .\.sonar\scanner\dotnet-sonarscanner begin `
100- /k:"jerone_Jvw.DevToys.SemverCalculator" `
101- /o:"jerone" `
102- /d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
103- /d:sonar.host.url="https://sonarcloud.io" `
104- /d:sonar.exclusions="**/Pack/**/*.xml" `
105- /d:sonar.verbose=true
128+ .\.sonar\scanner\dotnet-sonarscanner begin `
129+ /k:"jerone_Jvw.DevToys.SemverCalculator" `
130+ /o:"jerone" `
131+ /d:sonar.token="${{ secrets.SONAR_TOKEN }}" `
132+ /d:sonar.host.url="https://sonarcloud.io" `
133+ /d:sonar.exclusions="**/Pack/**/*.xml" `
134+ /d:sonar.verbose=true `
135+ /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
106136
107137 - name : Build solution
108- run : dotnet build
138+ run : dotnet build --no-incremental
139+
140+ - name : Test solution
141+ run : dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
142+ # https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/dotnet-test-coverage/#dotnetcoverage
109143
110144 - name : End SonarCloud analyze
111145 env :
@@ -115,7 +149,7 @@ jobs:
115149 run : |
116150 .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
117151
118- nuget_pack :
152+ job_nuget_pack :
119153 name : Pack NuGet package
120154 runs-on : ubuntu-latest
121155 steps :
@@ -124,7 +158,7 @@ jobs:
124158 - name : Setup .NET
125159 uses : actions/setup-dotnet@v4
126160 with :
127- dotnet-version : " 8 "
161+ global-json-file : " ./global.json "
128162
129163 - name : Set version variable
130164 if : ${{ github.ref_type == 'tag' }}
@@ -146,15 +180,20 @@ jobs:
146180 name : ${{ env.NuGetArtifactName }}
147181 path : ${{ env.NuGetDirectory }}/*.nupkg
148182
149- nuget_validate :
183+ job_nuget_validate :
150184 name : Validate NuGet package
151185 runs-on : ubuntu-latest
152- needs : [nuget_pack ]
186+ needs : [job_nuget_pack ]
153187 steps :
188+ - uses : actions/checkout@v4
189+ with :
190+ sparse-checkout : " global.json" # Only need this file for this job.
191+ sparse-checkout-cone-mode : false
192+
154193 - name : Setup .NET
155194 uses : actions/setup-dotnet@v4
156195 with :
157- dotnet-version : " 8 "
196+ global-json-file : " ./global.json "
158197
159198 - name : Install nuget validator
160199 run : dotnet tool install Meziantou.Framework.NuGetPackageValidation.Tool --global
@@ -168,16 +207,28 @@ jobs:
168207 shell : pwsh
169208 run : meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
170209
171- nuget_publish :
210+ job_nuget_publish :
172211 name : Publish NuGet package
173212 runs-on : ubuntu-latest
174- needs : [nuget_validate, build_test, analyze_codeql, analyze_sonarcloud]
213+ needs :
214+ [
215+ job_build_test,
216+ job_lint,
217+ job_nuget_validate,
218+ job_analyze_codeql,
219+ job_analyze_sonarcloud,
220+ ]
175221 if : github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
176222 steps :
223+ - uses : actions/checkout@v4
224+ with :
225+ sparse-checkout : " global.json" # Only need this file for this job.
226+ sparse-checkout-cone-mode : false
227+
177228 - name : Setup .NET
178229 uses : actions/setup-dotnet@v4
179230 with :
180- dotnet-version : " 8 "
231+ global-json-file : " ./global.json "
181232
182233 - uses : actions/download-artifact@v4
183234 with :
@@ -187,10 +238,10 @@ jobs:
187238 - name : Publish NuGet package
188239 run : dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg -k ${{ secrets.NUGET_APIKEY }} -s https://api.nuget.org/v3/index.json
189240
190- release :
241+ job_release :
191242 name : Create release on GitHub
192243 runs-on : ubuntu-latest
193- needs : [nuget_publish ]
244+ needs : [job_nuget_publish ]
194245 permissions :
195246 contents : write # Needed to create a release.
196247 steps :
0 commit comments