-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
422 lines (400 loc) · 17.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
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
- group: sonarsource-build-variables
# ensure, it is not used anymore
- name: ARTIFACTORY_API_USER
value: unset
- group: artifactory_access
# ARTIFACTORY_URL https://repox.jfrog.io/repox => https://repox.jfrog.io/artifactory
# JFROG_URL https://repox.jfrog.io
# https://github.com/SonarSource/parent-oss/blob/master/pom.xml#L708-L711
- name: ARTIFACTORY_DEPLOY_USERNAME
value: $[variables.ARTIFACTORY_QA_DEPLOYER_USERNAME]
# ~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]
resources:
repositories:
- repository: commonTemplates
type: git
name: pipelines-yaml-templates
ref: refs/tags/v2.0.2
stages:
- stage: build_dotnet
displayName: 'Build, test and analyze .NET extension'
variables:
- name: buildConfiguration
value: 'Release'
- name: slnPath
value: 'omnisharp-dotnet/SonarLint.OmniSharp.DotNet.Services.sln'
jobs:
- job: dotnet_build_test_test_analyze
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
steps:
- task: DownloadSecureFile@1
displayName: 'Download snk file'
name: snk
inputs:
secureFile: SonarSourceSecret.snk
- powershell: |
# Reads the Sonar project version to use from the Java POM file
# Calculate the POM file path
$versionFilePath = "$env:BUILD_SOURCESDIRECTORY\pom.xml"
Write-Host "Reading the Sonar project version from '${versionFilePath}' ..."
# Read the version from the file
[xml]$versionProps = Get-Content "$versionFilePath"
$sonarProjectVersion = $versionProps.project.version.Replace("-SNAPSHOT", "")
Write-Host "Sonar project version is '${sonarProjectVersion}'"
# Set the variable to it can be used by other tasks
Write-Host "##vso[task.setvariable variable=SONAR_PROJECT_VERSION;]$sonarProjectVersion"
displayName: 'Fetch the analysis version from the Java pom.xml'
# Using the restore command directly seems to be the only way to explicitly limit the package feed used
- task: DotNetCoreCLI@2
displayName: 'Restore NuGet packages'
inputs:
command: 'restore'
projects: $(slnPath)
restoreArguments: '--locked-mode'
feedsToUse: config
nugetConfigPath: 'omnisharp-dotnet/nuget.config'
includeNuGetOrg: false
- template: prepare-sq-analysis-steps.yml@commonTemplates
parameters:
scannerMode: 'MSBuild'
projectKey: 'sonarlint-omnisharp-dotnet'
projectName: 'sonarlint-omnisharp-dotnet'
projectVersion: '$(SONAR_PROJECT_VERSION)'
# NOTE: we're using coverlet -> openxml format for code coverage so we can run on non-Windows agents
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Build.SourcesDirectory)/**/TestResults/coverage.**.xml"
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: Maven@3
displayName: 'Run Maven to download Omnisharp for building .NET plug-in'
env:
ARTIFACTORY_QA_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
ARTIFACTORY_PRIVATE_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
goals: 'generate-resources'
options: '-B --settings $(mavenSettings.secureFilePath) -Denable-repo=qa -DskipIts -Pdownload-omnisharp-for-building'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
- task: UseDotNet@2
inputs:
version: '7.0.307'
# Build and run can be invoked in a single "test" command.
# This could also execute the restore, but we'd want to work out how to limit the package feed used
- task: DotNetCoreCLI@2
displayName: 'Build and run .NET unit tests'
inputs:
command: 'test'
projects: $(slnPath)
configuration: $(buildConfiguration)
arguments: '-p:SignAssembly=true -p:AssemblyOriginatorKeyFile="$(snk.secureFilePath)" $(additionalMSBuildProperties) -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=opencover --no-restore'
testRunTitle: '.NET unit tests'
- task: PublishPipelineArtifact@1
displayName: 'Publish the jar content files as a pipeline artifact'
inputs:
path: omnisharp-dotnet/JarContentFiles
artifact: DotNetJarContentFiles
- task: SonarQubeAnalyze@5
inputs:
jdkversion: 'JAVA_HOME_17_X64'
- template: mend.yml@commonTemplates
parameters:
productName : 'SonarLint/OmniSharp'
# We're running two Mend scans in this pipeline, one for .NET and one for Java.
# They can't both have the same projectName. We'll use the default projectName for the Java
# project so it works with the releasability check.
projectName : 'SonarSource/sonarlint-omnisharp/dotnet'
releaseVersion: '$(SONAR_PROJECT_VERSION)'
# Using a different agent config file for the .NET scan
configFilePath: '$(Build.SourcesDirectory)/omnisharp-dotnet/build/whitesource/wss-unified-agent.config'
- template: stage-with-burgr-notifications.yml@commonTemplates
parameters:
burgrName: 'build'
burgrType: 'build'
stageName: 'build'
stageDisplayName: Build and stage to repox
stageDependencies: build_dotnet
jobs:
- job: build
displayName: Build and stage to repox
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
commonMavenArguments: -B -Pdeploy-sonarsource -Dmaven.test.skip=true
fixedBranch: $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')]
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'build | maven | "$(Agent.OS)" | **/pom.xml, !its/**'
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: DownloadPipelineArtifact@2
displayName: 'Download .NET artifacts'
inputs:
source: current
artifact: DotNetJarContentFiles
path: omnisharp-dotnet/JarContentFiles
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: DownloadSecureFile@1
displayName: 'Download the sign key'
name: pgpSignKey
inputs:
secureFile: 'sign-key.asc'
- template: update-maven-version-steps.yml
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: Maven@3
displayName: 'Run Maven deploy and sign'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
env:
ARTIFACTORY_DEPLOY_PASSWORD: $(ARTIFACTORY_QA_DEPLOYER_ACCESS_TOKEN)
PGP_PASSPHRASE: $(PGP_PASSPHRASE)
GIT_SHA1: $(Build.SourceVersion)
GITHUB_BRANCH: $(fixedBranch)
inputs:
goals: 'deploy'
options: >-
$(commonMavenArguments)
--settings $(mavenSettings.secureFilePath)
-Prelease,sign
-Dsign.keyFile=$(pgpSignKey.secureFilePath)
-DskipIts
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
- task: Maven@3
displayName: 'Run Maven deploy'
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
env:
ARTIFACTORY_DEPLOY_PASSWORD: $(ARTIFACTORY_QA_DEPLOYER_ACCESS_TOKEN)
inputs:
goals: 'deploy'
options: >-
$(commonMavenArguments)
--settings $(mavenSettings.secureFilePath)
-DskipIts
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
- bash: git checkout .
name: revertPomChanges
displayName: Revert changes made to pom.xml to not break cache feature
- template: stage-with-burgr-notifications.yml@commonTemplates
parameters:
burgrName: 'validate'
burgrType: 'validate'
stageName: 'validate'
stageDisplayName: Run UTs and trigger SonarQube analysis
stageDependencies: build_dotnet
jobs:
- job: test_windows
displayName: Run unit tests on Windows
pool:
vmImage: 'windows-latest'
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'validate_win | maven | "$(Agent.OS)" | **/pom.xml, !its/**'
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: DownloadPipelineArtifact@2
displayName: 'Download .NET artifacts'
inputs:
source: current
artifact: DotNetJarContentFiles
path: omnisharp-dotnet/JarContentFiles
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: Maven@3
displayName: 'Run Maven verify'
env:
ARTIFACTORY_PRIVATE_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
goals: 'verify'
options: '-B --settings $(mavenSettings.secureFilePath) -DskipIts'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'UTs on Windows'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
- job: test_linux
displayName: Run unit tests on Linux
pool:
vmImage: 'ubuntu-latest'
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'validate_linux | maven | "$(Agent.OS)" | **/pom.xml, !its/**'
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: DownloadPipelineArtifact@2
displayName: 'Download .NET artifacts'
inputs:
source: current
artifact: DotNetJarContentFiles
path: omnisharp-dotnet/JarContentFiles
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: Maven@3
displayName: 'Run Maven verify'
env:
ARTIFACTORY_PRIVATE_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
goals: 'verify'
options: '-B --settings $(mavenSettings.secureFilePath) -DskipIts'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'UTs on Linux'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
- job: sonarqube
displayName: SonarQube analysis on Next and Mend analysis
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
steps:
- task: Cache@2
inputs:
key: 'sq | maven | "$(Agent.OS)" | **/pom.xml, !its/**'
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: DownloadPipelineArtifact@2
displayName: 'Download .NET artifacts'
inputs:
source: current
artifact: DotNetJarContentFiles
path: omnisharp-dotnet/JarContentFiles
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- template: prepare-sq-analysis-steps.yml
- task: Maven@3
env:
ARTIFACTORY_PRIVATE_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
goals: 'verify'
options: -B --settings $(mavenSettings.secureFilePath) -Pcoverage -DskipIts
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- template: mend-with-maven-repox.yml@commonTemplates
parameters:
# NB using the default projectName for this scan so it works with the releasability check.
# The .NET Mend scan (above) uses a custom projectName.
productName : 'SonarLint/OmniSharp'
mavenRepositoryPath: '$(MAVEN_CACHE_FOLDER)'
mavenSettingsFilePath: '$(mavenSettings.secureFilePath)'
- template: stage-with-burgr-notifications.yml@commonTemplates
parameters:
burgrName: 'qa'
burgrType: 'qa'
stageName: 'qa'
stageDisplayName: Run ITs
stageDependencies: build
jobs:
- job: its
displayName: Run ITs
strategy:
matrix:
Linux:
imageName: 'ubuntu-latest'
Windows:
imageName: 'windows-latest'
MacOS:
imageName: 'macOS-latest'
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Xmx3072m -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
pool:
vmImage: $(imageName)
steps:
- checkout: self
fetchDepth: 1
- task: Cache@2
inputs:
key: 'its | maven | "$(Agent.OS)" | **/pom.xml'
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- template: update-maven-version-steps.yml
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: UseDotNet@2
inputs:
version: '8.0.x'
- task: Maven@3
displayName: 'Run Maven ITs for SQ'
env:
ARTIFACTORY_QA_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
# For Orchestrator (https://github.com/SonarSource/orchestrator/commit/d5396c75ab77e6088afe58e61b0cd0693ac885f0)
ARTIFACTORY_ACCESS_TOKEN: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
GITHUB_TOKEN: $(GITHUB_TOKEN)
# SonarLintInstaller
MAVEN_LOCAL_REPOSITORY: $(MAVEN_CACHE_FOLDER)
inputs:
goals: 'verify'
mavenPomFile: 'its/pom.xml'
options: '-X -B --settings $(mavenSettings.secureFilePath) -Denable-repo=qa -DskipTests=false -Pdownload-staged-artifact'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'ITs $(imageName)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
- bash: git checkout .
name: revertPomChanges
displayName: Revert changes made to pom.xml to not break cache feature
- template: promote-stage.yml@commonTemplates
parameters:
stageDependencies:
- validate
- qa