Skip to content

Commit 8792cbc

Browse files
committed
add sonarcloud scan
1 parent 85e5f61 commit 8792cbc

5 files changed

Lines changed: 37 additions & 6 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec
3838
- Delete ArgoCD configs
3939
- Add Renovate dashboard link to README
4040
- Update GitVersion tasks in Azure DevOps
41+
- Add SonarCloud scan to Azure DevOps PR validation

build/auth-azure-pipelines-pr-validation.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ stages:
3535
buildConfiguration: 'Release'
3636
backendProjectPath: '$(System.DefaultWorkingDirectory)/src/authorization/EventTriangleAPI.Authorization.Presentation'
3737
unitTestsProjectPath: '$(System.DefaultWorkingDirectory)/src/authorization/EventTriangleAPI.Authorization.UnitTests/EventTriangleAPI.Authorization.UnitTests.csproj'
38-
shouldRunUnitTests: 'true'
39-
shouldRunIntegrationTests: 'true'
38+
shouldRunUnitTests: true
39+
shouldRunIntegrationTests: true
4040
integrationTestsProjectPath: '$(System.DefaultWorkingDirectory)/src/authorization/EventTriangleAPI.Authorization.IntegrationTests/EventTriangleAPI.Authorization.IntegrationTests.csproj'
4141
dockerRegistryUrl: 'docker.io/kaminome'
4242
dockerBuildParameterUrl: 'https://auth-eventtriangle.razumovsky.me/'
@@ -45,6 +45,7 @@ stages:
4545
dockerServiceConnection: 'Docker_Hub_Connection'
4646
acrRegistryUrl: 'acrsharedd01.azurecr.io'
4747
acrServiceConnection: 'Azure_ACR_Connection'
48+
sonarCloudEnabled: true
4849
workingDirectoryForDocker: '$(System.DefaultWorkingDirectory)/src'
4950

5051
# - stage: 'AKS_Helm_Deploy_${{ variables.appName }}'

build/consumer-azure-pipelines-pr-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ stages:
4848
dockerServiceConnection: 'Docker_Hub_Connection'
4949
acrRegistryUrl: 'acrsharedd01.azurecr.io'
5050
acrServiceConnection: 'Azure_ACR_Connection'
51+
sonarCloudEnabled: true
5152
workingDirectoryForDocker: '$(System.DefaultWorkingDirectory)/src'
5253

5354
# - stage: 'AKS_Helm_Deploy_${{ variables.appName }}'

build/sender-azure-pipelines-pr-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ stages:
4848
dockerServiceConnection: 'Docker_Hub_Connection'
4949
acrRegistryUrl: 'acrsharedd01.azurecr.io'
5050
acrServiceConnection: 'Azure_ACR_Connection'
51+
sonarCloudEnabled: true
5152
workingDirectoryForDocker: '$(System.DefaultWorkingDirectory)/src'

build/templates/docker-build-push-jobs.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ parameters:
2727

2828
- name: shouldRunUnitTests
2929
displayName: 'Flag should run unit tests'
30-
default: 'true'
30+
default: true
3131
type: boolean
3232

3333
- name: shouldRunIntegrationTests
@@ -36,7 +36,7 @@ parameters:
3636

3737
- name: integrationTestsProjectPath
3838
displayName: 'Integration tests project path'
39-
type: string
39+
type: boolean
4040

4141
- name: gitVersionVersion
4242
displayName: 'GitVersion version'
@@ -72,6 +72,11 @@ parameters:
7272
default: 'https://auth.eventtriangle.razumovsky.me/'
7373
type: string
7474

75+
- name: sonarCloudEnabled
76+
displayName: 'Is SonarCloud scan enabled'
77+
default: false
78+
type: boolean
79+
7580
jobs:
7681
- job: ${{ parameters.JobName }}
7782
displayName: ${{ parameters.JobName }}
@@ -102,22 +107,44 @@ jobs:
102107
arguments: '--verbosity minimal'
103108
nugetConfigPath: 'nuget.config'
104109

110+
- ${{ if eq(parameters.sonarCloudEnabled, true) }}:
111+
- task: SonarCloudPrepare@4
112+
inputs:
113+
SonarCloud: SonarCloud_Service_Connection
114+
organization: event-triangle
115+
scannerMode: dotnet
116+
projectKey: event-triangle_eventtriangleapi
117+
projectName: eventtriangleapi
118+
extraProperties: |
119+
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx
120+
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*opencover.xml
121+
sonar.exclusions=**/Properties/**, **/bin/**, **/obj/**, **/Migrations/**
122+
105123
- task: DotNetCoreCLI@2
106124
displayName: 'Build solution'
107125
inputs:
108126
command: 'build'
109127
projects: '${{ parameters.solution }}'
110128
arguments: '-c ${{ parameters.buildConfiguration }} -p:Version=$(version_step.semVer) --no-restore'
111129

112-
- ${{ if eq(parameters.shouldRunUnitTests, 'true') }}:
130+
- ${{ if eq(parameters.sonarCloudEnabled, true) }}:
131+
- task: SonarCloudAnalyze@4
132+
inputs: {}
133+
134+
- ${{ if eq(parameters.sonarCloudEnabled, true) }}:
135+
- task: SonarCloudPublish@4
136+
inputs:
137+
pollingTimeoutSec: "300"
138+
139+
- ${{ if eq(parameters.shouldRunUnitTests, true) }}:
113140
- task: DotnetCoreCLI@2
114141
displayName: 'Run unit tests'
115142
inputs:
116143
command: 'test'
117144
projects: '${{ parameters.unitTestsProjectPath }}'
118145
arguments: '--no-build --configuration ${{ parameters.buildConfiguration }} --collect "Code Coverage"'
119146

120-
- ${{ if eq(parameters.shouldRunIntegrationTests, 'true') }}:
147+
- ${{ if eq(parameters.shouldRunIntegrationTests, true) }}:
121148
- task: DotNetCoreCLI@2
122149
displayName: 'Run integration tests'
123150
inputs:

0 commit comments

Comments
 (0)