forked from MethodsAndPractices/vsteam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
332 lines (283 loc) · 10.6 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
name: $(Build.BuildID)
trigger:
- trunk
resources:
- repo: self
variables:
Folder: 'dist'
TEAM_CIBUILD: 'true'
PESTER_VERSION: '5.1.1'
stages:
- stage: Build
displayName: Build Stage
jobs:
- job: Linux_Phase
displayName: Build Linux
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .build/unitTests.yml
parameters:
os: 'Linux'
buildHelp: 'false'
- task: PowerShell@2
displayName: 'Install PSScriptAnalyzer'
inputs:
pwsh: true
targetType: 'inline'
script: 'Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser -Verbose'
- task: PowerShell@2
displayName: 'Run Static Code Analysis'
inputs:
pwsh: true
targetType: 'inline'
script: |
# Has to happen in this task for it to take effect
# Load the psd1 file so you can read the required modules and import them
$manifest = Import-PowerShellDataFile .\dist\*.psd1
# Import each module
$manifest.RequiredModules | ForEach-Object { Import-Module -Name $_ }
$count = 0
$r = Invoke-ScriptAnalyzer –Path ./dist –Recurse | Where-Object severity -ne "Information"
$r | ForEach-Object {Write-Host "##vso[task.logissue type=error;sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)"; $count++}
if($count -ne 0) {
Write-Host "##vso[task.complete result=Failed;]Static Code Analysis with error count = $count"
}
- job: macOS_Phase
displayName: Build macOS
pool:
vmImage: 'macOS-latest'
steps:
- template: .build/unitTests.yml
parameters:
os: 'macOS'
buildHelp: 'true'
- task: CopyFiles@2
displayName: 'Copy Module to Artifacts Folder'
inputs:
Contents: |
README.md
.gitignore
dist/**
TargetFolder: '$(build.artifactstagingdirectory)/VSTeam'
flattenFolders: false
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
- task: PublishPipelineArtifact@1
displayName: 'Publish Module'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/VSTeam'
artifact: 'module'
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
- task: CopyFiles@2
displayName: 'Copy Integration Tests Artifacts Folder'
inputs:
Contents: |
Tests/SampleFiles/**
Tests/integration/tests/**
TargetFolder: '$(build.artifactstagingdirectory)/Tests'
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
- task: CopyFiles@2
displayName: 'Copy psd1 to Integration Tests Artifacts Folder'
inputs:
Contents: |
dist/*.psd1
TargetFolder: '$(build.artifactstagingdirectory)/Tests'
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
- task: PublishPipelineArtifact@1
displayName: 'Publish Tests'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/Tests'
artifact: 'test'
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
- job: Windows_Phase
displayName: Build Windows
pool:
vmImage: 'windows-latest'
steps:
- template: .build/unitTests.yml
parameters:
os: 'Windows'
buildHelp: 'false'
- task: CredScan@2
displayName: 'Run CredScan'
inputs:
toolMajorVersion: 'V2'
suppressionsFile: '$(Build.SourcesDirectory)/.build/credscan-supression.json'
- task: PostAnalysis@1
displayName: 'Post Analysis'
inputs:
AllTools: false
CredScan: true
- stage: Package
displayName: Package Management
dependsOn: Build
condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false))
jobs:
- deployment: Deploy
displayName: Package Management
pool:
vmImage: 'ubuntu-latest'
environment: 'Default'
strategy:
runOnce:
deploy:
steps:
- download: current
displayName: 'Download module'
artifact: module
- task: NuGetToolInstaller@0
displayName: 'Install NuGet 5.2.0'
inputs:
versionSpec: 5.2.0
- task: PowerShell@2
displayName: 'Install Module Dependencies'
inputs:
pwsh: true
targetType: 'inline'
script: |
# Load the psd1 file so you can read the required modules and install them
$manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1
# Install each module
$manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -Force -Scope CurrentUser -Verbose }
workingDirectory: '$(Pipeline.Workspace)/module'
- task: PowerShell@2
displayName: 'Compute Version Number'
inputs:
pwsh: true
targetType: 'inline'
script: |
# Load the psd1 file so you can read the version
$manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1
Write-Host "Package Version Number: $($manifest.ModuleVersion).$(Build.BuildId)"
Write-Host "##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$($manifest.ModuleVersion).$(Build.BuildId)"
workingDirectory: '$(Pipeline.Workspace)/module'
- task: PowerShell@2
displayName: 'Create NuSpec from PSD1'
inputs:
pwsh: true
targetType: 'inline'
script: |
Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose
Write-Host "Convert psd1 into a NuSpec"
ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1 -Verbose
workingDirectory: '$(Pipeline.Workspace)/module'
- task: NuGetCommand@2
displayName: 'Pack Module'
inputs:
command: pack
packagesToPack: '$(Pipeline.Workspace)/module/$(Folder)/VSTeam.nuspec'
packDestination: '$(Pipeline.Workspace)/module/$(Folder)'
versioningScheme: byEnvVar
versionEnvVar: 'PACKAGE_VERSION'
- task: NuGetCommand@2
displayName: 'Push Module'
inputs:
command: push
packagesToPush: '$(Pipeline.Workspace)/module/$(Folder)/*.nupkg'
publishVstsFeed: 'vsteam'
allowPackageConflicts: true
- stage: Testing
displayName: Testing stage
dependsOn: Package
jobs:
- template: .build/integrationTests.yml
parameters:
displayName: 'Linux TFS 2018'
os: 'Linux'
pool: 'ubuntu-latest'
start2018: 'true'
stop2018: 'true'
name: 'LinuxTFS2018'
apiVersion: 'TFS2018'
account: 'http://winbldbox3.centralus.cloudapp.azure.com:8080/tfs/defaultcollection'
- template: .build/integrationTests.yml
parameters:
displayName: 'Windows AzD'
os: 'Windows'
pool: 'windows-latest'
name: 'windowsAzD'
apiVersion: 'VSTS'
account: 'tooltester'
- template: .build/integrationTests.yml
parameters:
displayName: 'macOS TFS 2017'
os: 'macOS'
pool: 'macOS-latest'
start2017: 'true'
stop2017: 'true'
name: 'macOSTFS2017'
apiVersion: 'TFS2017'
account: 'http://sonarqube.eastus2.cloudapp.azure.com:8080/tfs/vsteam'
- stage: Production
displayName: PowerShell Gallery / GitHub Release
dependsOn: Testing
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/trunk'))
jobs:
- deployment: Deploy
displayName: PowerShell Gallery / GitHub Release
pool:
vmImage: 'windows-latest'
environment: 'PowerShell Gallery'
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: module
- task: NuGetToolInstaller@0
displayName: 'Install NuGet 5.2.0'
inputs:
versionSpec: 5.2.0
- task: PowerShell@2
displayName: 'Install Module Dependencies'
inputs:
pwsh: true
targetType: 'inline'
script: |
# Load the psd1 file so you can read the required modules and install them
$manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1
# Install each module
$manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser }
workingDirectory: '$(Pipeline.Workspace)/module'
- task: PowerShell@2
displayName: 'Create NuSpec from PSD1'
inputs:
pwsh: true
targetType: 'inline'
script: |
Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose
ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1
# Load the psd1 file so you can read the version
$manifest = Import-PowerShellDataFile ./$(Folder)/VSTeam.psd1
Write-Host "##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$($manifest.ModuleVersion)"
workingDirectory: '$(Pipeline.Workspace)/module'
- task: NuGetCommand@2
displayName: 'Pack Module'
inputs:
command: pack
packagesToPack: '$(Pipeline.Workspace)/module/$(Folder)/VSTeam.nuspec'
packDestination: '$(Pipeline.Workspace)/module/$(Folder)'
- task: PublishPipelineArtifact@1
displayName: 'Publish nupkg Artifact'
inputs:
targetPath: '$(Pipeline.Workspace)/module/$(Folder)'
artifact: 'Package'
publishLocation: 'pipeline'
- task: NuGetCommand@2
displayName: 'Push Module'
inputs:
command: push
packagesToPush: '$(Pipeline.Workspace)/module/$(Folder)/*.nupkg'
nuGetFeedType: external
publishFeedCredentials: 'PowerShell Gallery'
- task: GithubRelease@0
displayName: 'Create GitHub Release'
inputs:
gitHubConnection: Darquewarrior
repositoryName: MethodsAndPractices/vsteam
tagSource: manual
tag: v$(PACKAGE_VERSION)
addChangeLog: true
compareWith: 'lastFullRelease'
assets: |
$(Pipeline.Workspace)/module/$(Folder)/*.nupkg