-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
168 lines (144 loc) · 7.16 KB
/
azure-pipelines.yml
File metadata and controls
168 lines (144 loc) · 7.16 KB
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
trigger:
- master
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: UnitTestResultsPath
value: '$(Build.SourcesDirectory)\TestResults'
- name: CoveragePath
value: '$(Build.SourcesDirectory)\coverage'
- name: UnitTestExclusionsPattern
value: 'analyzers/tests/SonarAnalyzer.Test/TestCases/**/*'
- name: CpdExclusionsPattern
value: 'analyzers/rspec/**'
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: build
displayName: 'Build'
workspace:
clean: all
steps:
- powershell: Rename-Item "analyzers/CI.NuGet.Config" -NewName "NuGet.Config"
displayName: "Prepare NuGet.Config"
- task: CmdLine@2
displayName: "NuGet Restore"
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
targetType: 'inline'
script: 'dotnet restore --locked-mode --configfile analyzers\NuGet.Config $(solution)'
- 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
- powershell: .\scripts\set-version.ps1 -Version $(SHORT_VERSION) -BuildNumber $(Build.BuildId) -Branch $(Build.SourceBranchName) -Sha1 $(Build.SourceVersion)
displayName: "Set Version"
- task: SonarCloudPrepare@3
displayName: '.NET Code Analysis - Begin'
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: dotnet
projectKey: 'sonaranalyzer-dotnet'
projectName: 'Sonar .NET Analyzer'
projectVersion: '$(SHORT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(CoveragePath)/*.xml"
sonar.cs.vstest.reportsPaths="$(UnitTestResultsPath)/*.trx"
sonar.test.exclusions="$(UnitTestExclusionsPattern)"
sonar.cpd.exclusions=$(CpdExclusionsPattern)
- powershell: |
$ProjectNameToken = '$(ProjectName)' # Workaround for escaping difficulties: Azure DevOps doesn't have ProjectName, so it will not replace it. We need to pass it like that into AltCover via powershell.
dotnet build --no-restore analyzers\src\SonarAnalyzer.ShimLayer.Generator\SonarAnalyzer.ShimLayer.Generator.csproj -c $(BuildConfiguration) # Needs a pre-build to prevent file locking issue in SonarAnalyzer.ShimLayer.Generator.Test
dotnet test --no-restore $(Solution) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:RunAnalyzers=true /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.$ProjectNameToken.xml"
displayName: '.NET UTs'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
- powershell: |
dotnet build analyzers\src\RuleDescriptorGenerator\RuleDescriptorGenerator.csproj -c $(BuildConfiguration) /p:RunAnalyzers=true # This does not have a test project => we need to build it separately
displayName: '.NET RuleDescriptor Build'
- task: PublishTestResults@2
condition: always()
displayName: 'Publish test results'
inputs:
testRunner: VSTest
testResultsFiles: '*.trx'
searchFolder: '$(UnitTestResultsPath)'
testRunTitle: '$(Agent.JobName)'
- script: |
nuget pack analyzers/packaging/SonarAnalyzer.CFG.nuspec -Version $(FULL_VERSION) -Properties Configuration=$(BuildConfiguration) -OutputDirectory $(Build.ArtifactStagingDirectory)/packages -Verbosity Detailed
nuget pack analyzers/packaging/SonarAnalyzer.CSharp.nuspec -Version $(FULL_VERSION) -Properties Configuration=$(BuildConfiguration) -OutputDirectory $(Build.ArtifactStagingDirectory)/packages -Verbosity Detailed
nuget pack analyzers/packaging/SonarAnalyzer.CSharp.Styling.nuspec -Version $(FULL_VERSION) -Properties Configuration=$(BuildConfiguration) -OutputDirectory $(Build.ArtifactStagingDirectory)/packages -Verbosity Detailed
nuget pack analyzers/packaging/SonarAnalyzer.VisualBasic.nuspec -Version $(FULL_VERSION) -Properties Configuration=$(BuildConfiguration) -OutputDirectory $(Build.ArtifactStagingDirectory)/packages -Verbosity Detailed
displayName: "Build NuGet packages"
- task: SonarCloudAnalyze@3
displayName: '.NET Code Analysis - End'
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: SonarCloudPrepare@3
displayName: 'Prepare code analysis for Java plugin'
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'Other'
- task: Maven@4
displayName: 'Maven build'
env:
ARTIFACTORY_PRIVATE_READER_USERNAME: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PRIVATE_READER_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
inputs:
goals: 'verify'
options: -B --settings $(mavenSettings.secureFilePath) -Pcoverage -Dsonar.projectVersion=$(SHORT_VERSION) -Denable-repo=private
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: '$(Agent.JobName)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.21'
mavenOptions: $(MAVEN_OPTS)
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- task: CopyFiles@2
displayName: "Copy C# Jars to publish directory"
inputs:
Contents: '*.jar'
SourceFolder: 'sonar-csharp-plugin/target'
TargetFolder: 'plugin-jars/sonar-csharp-plugin'
- task: CopyFiles@2
displayName: "Copy VB.NET Jars to publish directory"
inputs:
Contents: '*.jar'
SourceFolder: 'sonar-vbnet-plugin/target'
TargetFolder: 'plugin-jars/sonar-vbnet-plugin'
- publish: plugin-jars
artifact: plugin-jars
displayName: "Publish Jars as build artifacts"
- publish: '$(Build.ArtifactStagingDirectory)/packages'
artifact: 'NuGet Packages'
displayName: 'Publish NuGet packages as build artifacts'
- task: SonarCloudPublish@3
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'