-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
216 lines (187 loc) · 6.65 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
# Build for Angular project
trigger:
batch: true
branches:
include:
- '*'
pr:
branches:
include:
- '*'
variables:
artifactDirectory: lib
builtLibLocation: dist/godeltech/angular-testing
demoTestResultLocation: junit/demo
libCoverageLocation: coverage/lib
libLocation: projects/godeltech/angular-testing
libSrcLocation: projects/godeltech/angular-testing/src
libTestResultLocation: junit/lib
packageName: '@godeltech/angular-testing'
sonarCloudOrganizationName: godeltech
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Build
displayName: 'Build'
variables:
versionSuffix: ''
currentPackageVersion: ''
jobs:
- job: Lib
displayName: 'Build and test lib'
steps:
- task: NodeTool@0
displayName: 'Install Node.js'
inputs:
versionSpec: '10.x'
- task: Npm@1
displayName: 'Install npm'
inputs:
command: 'install'
- task: Bash@3
displayName: 'Set version suffix'
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=versionSuffix]-ci-$BUILD_BUILDNUMBER"
- task: PowerShell@2
displayName: 'Get current version'
inputs:
targetType: 'inline'
workingDirectory: '$(System.DefaultWorkingDirectory)/$(libLocation)'
script: |
npm version | ConvertFrom-Json | Select-Object -ExpandProperty $(packageName) | Set-Variable -Name packageVersion
Write-Host "##vso[task.setvariable variable=currentPackageVersion;]$packageVersion"
- task: PowerShell@2
displayName: 'Update version'
condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
inputs:
targetType: 'inline'
workingDirectory: '$(System.DefaultWorkingDirectory)/$(libLocation)'
script: |
npm --no-git-tag-version version $(currentPackageVersion)$(versionSuffix)
- task: SonarCloudPrepare@1
displayName: 'Prepare SonarCloud Analysis Configuration'
inputs:
SonarCloud: 'SonarCloud'
organization: '$(sonarCloudOrganizationName)'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: '$(Build.DefinitionName)'
cliProjectName: '$(Build.DefinitionName)'
cliProjectVersion: '$(currentPackageVersion)$(versionSuffix)'
cliSources: '$(System.DefaultWorkingDirectory)/$(libSrcLocation)'
extraProperties: |
sonar.exclusions=**/node_modules/**,**/*.spec.ts
sonar.tests=$(System.DefaultWorkingDirectory)/$(libSrcLocation)
sonar.test.inclusions=$(System.DefaultWorkingDirectory)/$(libSrcLocation)/**/*.spec.ts
sonar.ts.tslintconfigpath=$(System.DefaultWorkingDirectory)/tslint.json
sonar.typescript.lcov.reportPaths=$(System.DefaultWorkingDirectory)/$(libCoverageLocation)/lcov.info
sonar.typescript.exclusions=**/node_modules/**,**/typings.d.ts,**/main.ts,**/environments/environment*.ts,**/*routing.module.ts
- task: Npm@1
displayName: 'Build'
inputs:
command: 'custom'
customCommand: 'run build:lib'
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifac in $(artifactDirectory) directory'
inputs:
path: '$(System.DefaultWorkingDirectory)/$(builtLibLocation)'
artifact: '$(artifactDirectory)'
- task: Npm@1
displayName: 'Test'
inputs:
command: 'custom'
customCommand: 'run test:lib'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage result'
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(libCoverageLocation)/cobertura-coverage.xml'
failIfCoverageEmpty: true
- task: PublishTestResults@2
displayName: 'Publish test result'
condition: succeededOrFailed()
inputs:
searchFolder: $(System.DefaultWorkingDirectory)/$(libTestResultLocation)
testRunTitle: lib
testResultsFormat: JUnit
testResultsFiles: "**/TESTS*.xml"
- task: SonarCloudAnalyze@1
displayName: 'Run Code Analysis'
- task: SonarCloudPublish@1
displayName: 'Publish Quality Gate Result'
inputs:
pollingTimeoutSec: '300'
- task: sonarcloud-buildbreaker@2
displayName: 'Break build on quality gate failure'
inputs:
SonarCloud: 'SonarCloud'
organization: '$(sonarCloudOrganizationName)'
- job: Demo
displayName: 'Build and test demo'
steps:
- task: NodeTool@0
displayName: 'Install Node.js'
inputs:
versionSpec: '10.x'
- task: Npm@1
displayName: 'Install npm'
inputs:
command: 'install'
- task: Npm@1
displayName: 'Build'
inputs:
command: 'custom'
customCommand: 'run build:demo'
- task: Npm@1
displayName: 'Test'
inputs:
command: 'custom'
customCommand: 'run test:demo'
- task: PublishTestResults@2
displayName: 'Publish tests result'
condition: succeededOrFailed()
inputs:
searchFolder: $(System.DefaultWorkingDirectory)/$(demoTestResultLocation)
testRunTitle: demo
testResultsFormat: JUnit
testResultsFiles: "**/TESTS*.xml"
- stage: Artifacts
displayName: 'Artifacts'
dependsOn: Build
jobs:
- deployment: Publish
displayName: 'Publish lib in artifacts'
environment: 'Artifacts'
strategy:
runOnce:
deploy:
steps:
- task: Npm@1
displayName: 'Publish lib in artifacts'
inputs:
command: 'publish'
workingDir: '$(Pipeline.Workspace)/$(artifactDirectory)'
publishRegistry: 'useFeed'
publishFeed: '19324bbd-9baf-4407-b86d-3e7f0d145399/0df141cc-6c8d-4e42-a363-89cd9c930d8e'
- stage: Npm
displayName: 'Npm'
dependsOn: Artifacts
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment: Publish
displayName: 'Publish lib in npm registry'
environment: 'npm'
strategy:
runOnce:
deploy:
steps:
- task: Npm@1
displayName: 'Publish lib in npm registry'
inputs:
command: 'publish'
workingDir: '$(Pipeline.Workspace)/$(artifactDirectory)'
publishEndpoint: 'npm'