-
Notifications
You must be signed in to change notification settings - Fork 229
/
azure-pipelines.yml
436 lines (380 loc) · 15.4 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
schedules:
# Run from Monday to Friday at 5:30 UTC (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#cron-syntax)
- cron: "30 5 * * 1-5"
displayName: Daily build
branches:
include:
- master
- branch-*
always: true
trigger:
- master
- branch-*
pool: .net-bubble-aws-re-team-prod
variables:
- group: sonar-dotnet-variables
- group: sonarsource-build-variables
- group: artifactory_access
# ~https://github.com/SonarSource/re-ci-images/blob/master/docker/mvn/settings-private.xml
- name: ARTIFACTORY_PRIVATE_USERNAME
value: $[variables.ARTIFACTORY_PRIVATE_READER_USERNAME]
- name: ARTIFACTORY_QA_READER_USERNAME
value: $[variables.ARTIFACTORY_PRIVATE_READER_USERNAME]
- name: UnitTestProjectPath
value: 'analyzers\tests\SonarAnalyzer.Test\'
- name: UnitTestResultsPath
value: '$(Build.SourcesDirectory)\TestResults'
- name: CoveragePath
value: '$(Build.SourcesDirectory)\coverage'
- name: UnitTestExclusionsPattern
value: 'analyzers/tests/SonarAnalyzer.Test/TestCases/**/*'
- name: vsVersion
value: '17.0'
resources:
repositories:
- repository: pipelines-yaml-templates
type: git
name: pipelines-yaml-templates
ref: refs/tags/v3.0.0
stages:
- stage: build
displayName: 'Build:'
jobs:
- job: dotnetBuildjob
displayName: 'Build and package'
workspace:
clean: all
steps:
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- script: '"$(MSBUILD_PATH)" /t:restore /p:RestoreLockedMode=true /p:RestoreConfigFile="analyzers\NuGet.Config" $(solution)'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
displayName: "NuGet Restore"
- powershell: .\scripts\build\store-azp-variables.ps1
displayName: "Store AZP Variables"
- publish: $(Agent.BuildDirectory)/Azp-Variables
artifact: Azp-Variables
displayName: "Publish AZP Variables as pipeline artifact"
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: VSBuild@1
displayName: 'Set BranchName, Sha1 and BuildNumber'
inputs:
solution: scripts/version/ChangeVersion.proj
msbuildArgs: '/p:Sha1=$(Build.SourceVersion) /p:BranchName=$(Build.SourceBranchName) /p:BuildNumber=$(Build.BuildId) /p:BuildConfiguration=$(BuildConfiguration)'
vsVersion: $(vsVersion)
- task: VSBuild@1
displayName: "Build SonarAnalyzer solution"
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:Sha1=$(Build.SourceVersion) /p:BuildNumber=$(Build.BuildId) /p:WarningLevel=0'
vsVersion: $(vsVersion)
- task: NuGetCommand@2
displayName: "Build NuGet packages"
inputs:
command: pack
packagesToPack: 'analyzers/src/**/*.nuspec;analyzers/packaging/*.nuspec'
configuration: '$(BuildConfiguration)'
packDestination: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'Detailed'
publishPackageMetadata: true
- task: PublishBuildArtifacts@1
displayName: 'Publish NuGet packages as build artifacts'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/packages'
artifactName: 'NuGet Packages'
- task: PublishPipelineArtifact@1
displayName: 'Publish analyzer binaries as pipeline artifact'
inputs:
path: analyzers/packaging/binaries/
artifact: Binaries
- task: PublishPipelineArtifact@1
displayName: 'Publish analyzer test binaries as pipeline artifact'
inputs:
path: '$(UnitTestProjectPath)\bin'
artifact: TestBinaries
- stage: qa
# .NET code analysis, UTs, ITs, build Java and publish SC QG
displayName: 'Tests:'
dependsOn: build
jobs:
- job: runUnitTestsDotNet
displayName: '.NET UTs'
workspace:
clean: all
strategy:
matrix:
Net48:
CoverageArtifactName: 'DotNetCoverageNet48'
TestResultsArtifactName: 'DotNetTestResultsNet48'
ProjectFilePath: 'tests\SonarAnalyzer.Test\SonarAnalyzer.Test.csproj'
FrameworkMoniker: 'net48'
Net80:
CoverageArtifactName: 'DotNetCoverageNet8'
TestResultsArtifactName: 'DotNetTestResultsNet8'
ProjectFilePath: 'tests\SonarAnalyzer.Test\SonarAnalyzer.Test.csproj'
FrameworkMoniker: 'net8.0'
Styling:
CoverageArtifactName: 'DotNetCoverageStyling'
TestResultsArtifactName: 'DotNetTestResultsStyling'
ProjectFilePath: 'tests\SonarAnalyzer.CSharp.Styling.Test\SonarAnalyzer.CSharp.Styling.Test.csproj'
FrameworkMoniker: 'net8.0'
TestFramework:
CoverageArtifactName: 'DotNetCoverageTestFramework'
TestResultsArtifactName: 'DotNetTestResultsTestFramework'
ProjectFilePath: 'tests\SonarAnalyzer.TestFramework.Test\SonarAnalyzer.TestFramework.Test.csproj'
FrameworkMoniker: 'net8.0'
ITs.JsonParser:
CoverageArtifactName: 'ITs.JsonParserCoverage'
TestResultsArtifactName: 'ITs.JsonParserResults'
ProjectFilePath: 'tests\ITs.JsonParser.Test\ITs.JsonParser.Test.csproj'
FrameworkMoniker: 'net8.0'
steps:
- task: UseDotNet@2
displayName: Use .NET
inputs:
packageType: 'sdk'
version: 8.0.300
- task: DownloadPipelineArtifact@2
displayName: 'Download binaries to test'
inputs:
artifact: TestBinaries
targetPath: '$(UnitTestProjectPath)\bin'
- powershell: |
cd analyzers
& dotnet test $(ProjectFilePath) -f $(FrameworkMoniker) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter="testhost|Moq|Humanizer|AltCover|Microsoft|\.Test^",AltCoverPathFilter="SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration",AltCoverAttributeFilter="ExcludeFromCodeCoverage",AltCoverReport="$(CoveragePath)/coverage.$(CoverageArtifactName).xml"
displayName: '.Net UTs'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
- task: PublishPipelineArtifact@1
displayName: 'Save coverage files'
inputs:
path: '$(CoveragePath)'
artifact: $(CoverageArtifactName)
- task: PublishPipelineArtifact@1
displayName: 'Save test results files'
inputs:
path: '$(UnitTestResultsPath)'
artifact: $(TestResultsArtifactName)
- task: PublishTestResults@2
condition: always()
displayName: 'Publish test results'
inputs:
testRunner: VSTest
testResultsFiles: '*.trx'
searchFolder: '$(UnitTestResultsPath)'
testRunTitle: '$(Agent.JobName)'
- job: dotNetAnalysis
displayName: '.Net Analysis'
workspace:
clean: all
# This job runs the .Net code analysis and uploads to SonarCloud the test results and coverage reports generated
# in previous jobs.
condition: eq(dependencies.runUnitTestsDotNet.result, 'Succeeded')
dependsOn:
- runUnitTestsDotNet
steps:
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: SonarCloudPrepare@2
displayName: 'Code Analysis - Begin (PR)'
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'MSBuild'
projectKey: 'sonaranalyzer-dotnet'
projectName: 'Sonar .NET Analyzer'
projectVersion: '$(SONAR_PROJECT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(CoveragePath)/*.xml"
sonar.cs.vstest.reportsPaths="$(UnitTestResultsPath)/*.trx"
sonar.test.exclusions="$(UnitTestExclusionsPattern)"
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(System.PullRequest.SourceCommitId)
sonar.analysis.prNumber=$(System.PullRequest.PullRequestNumber)
sonar.analysis.repository=$(Build.Repository.ID)
- task: SonarCloudPrepare@2
displayName: 'Code Analysis - Begin (master or branch)'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'MSBuild'
projectKey: 'sonaranalyzer-dotnet'
projectName: 'Sonar .NET Analyzer'
projectVersion: '$(SONAR_PROJECT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(CoveragePath)/*.xml"
sonar.cs.vstest.reportsPaths="$(UnitTestResultsPath)/*.trx"
sonar.test.exclusions="$(UnitTestExclusionsPattern)"
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(Build.SourceVersion)
sonar.analysis.repository=$(Build.Repository.ID)
- task: VSBuild@1
displayName: 'Set BranchName, Sha1 and BuildNumber properties from Azure pipeline variables'
inputs:
solution: scripts/version/ChangeVersion.proj
msbuildArgs: '/p:Sha1=$(Build.SourceVersion) /p:BranchName=$(Build.SourceBranchName) /p:BuildNumber=$(Build.BuildId) /p:BuildConfiguration=$(BuildConfiguration)'
vsVersion: $(vsVersion)
- script: '"$(MSBUILD_PATH)" /t:restore /p:RestoreLockedMode=true /p:RestoreConfigFile="analyzers\NuGet.Config" $(solution)'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
displayName: "NuGet Restore"
- task: VSBuild@1
displayName: "Run .Net code analysis"
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:RunAnalyzers=true'
vsVersion: $(vsVersion)
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotNetCoverageNet48
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotNetCoverageNet8
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotNetCoverageStyling
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotNetCoverageTestFramework
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: ITs.JsonParserCoverage
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotNetTestResultsNet48
targetPath: 'TestResults'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotNetTestResultsNet8
targetPath: 'TestResults'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotNetTestResultsStyling
targetPath: 'TestResults'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotNetTestResultsTestFramework
targetPath: 'TestResults'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: ITs.JsonParserResults
targetPath: 'TestResults'
- powershell: |
# Coverage is computed in another job and can have a different base path.
# We need to normalize content of the coverage files to the current VM job path.
# Values generated by the agent can look like this:
# `C:\sonar-ci\_work\1\s`
# `C:\sonar-ci\_work\2\s`
$CurrentPath = ${env:BUILD_SOURCESDIRECTORY}
$Pattern = [Regex]::Escape($CurrentPath) -Replace "\\\\\d+\\\\","\\\d+\\" # We replace the existing escaped "\\1\\" digit(s) with actual pattern to search for any other digit(s)
dir coverage\*.xml | % {
$Path = $_.FullName
Write-Host "Updating ${Path} to common root ${CurrentPath}"
(Get-Content -Path $Path -Raw) -Replace $Pattern,$CurrentPath | Set-Content $Path
}
displayName: Fix coverage paths
- task: SonarCloudAnalyze@2
displayName: 'Code Analysis - End'
- task: SonarCloudPublish@2
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'
- job: runJavaBuild
displayName: 'Java build'
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download .Net binaries for Maven build'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: DownloadSecureFile@1
displayName: 'Download the sign key'
name: signKey
inputs:
secureFile: 'sign-key.asc'
# Template below is in https://dev.azure.com/sonarsource/DotNetTeam%20Project/_git/pipelines-yaml-templates?path=/update-maven-version-steps.yml&version=GBmaster
# For more info see scripts/version/README.md
- template: update-maven-version-steps.yml@pipelines-yaml-templates
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- job: runJavaUnitTests
displayName: 'Java UTs'
dependsOn: runJavaBuild
workspace:
clean: all
steps:
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- template: update-maven-version-steps.yml@pipelines-yaml-templates
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: DownloadPipelineArtifact@2
displayName: 'Download .Net binaries for Maven build'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- task: SonarCloudPrepare@2
displayName: 'Prepare code analysis for Java plugin'
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'Other'
- task: Maven@3
displayName: 'Maven verify, UTs with SonarCloud'
inputs:
goals: 'verify'
options: -B --settings $(mavenSettings.secureFilePath) -Pcoverage -Dsonar.projectVersion=$(SONAR_PROJECT_VERSION)
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: '$(Agent.JobName)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- task: SonarCloudPublish@2
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'