-
Notifications
You must be signed in to change notification settings - Fork 157
325 lines (281 loc) · 9.98 KB
/
actions-pipeline.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
name: 'build module'
on:
workflow_dispatch:
push:
branches:
- trunk
paths:
- 'src/**'
- 'Tests/**'
- '.docs/**'
- '.github/'
- '!.github/images/'
- '!.github/*.md'
- '!.vscode/**'
- '!.devContainer/**'
- '!tools/**'
- '!.gitignore'
- '!LICENSE'
- '!*.md'
pull_request:
branches:
- trunk
jobs:
build-stage:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest,ubuntu-latest,macos-latest]
fail-fast: true
permissions:
checks: write
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: Cache NuGet packages
id: cache-nuget-packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Source/Classes/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: .NET Restore
if: steps.cache-nuget-packages.outputs.cache-hit != 'true'
shell: pwsh
run: dotnet restore --no-cache # have to use no cache of the build will fail on Windows
- name: Build module with help
if: ${{ matrix.os == 'windows-latest'}}
shell: pwsh
run: ./Build-Module.ps1 -installDep -configuration Release -buildHelp
- name: Build module without help
if: ${{ matrix.os != 'windows-latest'}}
shell: pwsh
run: ./Build-Module.ps1 -installDep -configuration Release
- name: Run C# unit tests
shell: pwsh
run: dotnet test --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed"
# - name: Publish C# test results
# if: success() || failure()
# uses: dorny/test-reporter@v1
# with:
# name: C# tests results (${{ matrix.os }})
# path: '**/test-results.trx'
# reporter: dotnet-trx
- name: Run PowerShell unit tests
shell: pwsh
run: |
Import-Module ./dist/*.psd1
# This loads [PesterConfiguration] into scope
Import-Module Pester
$pesterArgs = [PesterConfiguration]::Default
$pesterArgs.Run.Exit = $true
$pesterArgs.Run.Throw = $true
$pesterArgs.Run.PassThru = $false
$pesterArgs.TestResult.Enabled = $true
$pesterArgs.Output.Verbosity = 'Normal'
$pesterArgs.Run.Path = './Tests/function'
$pesterArgs.TestResult.OutputFormat = 'JUnitXml'
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
$env:VSTEAM_NO_UPDATE_MESSAGE = $true
$env:VSTEAM_NO_MODULE_MESSAGES = $true
Invoke-Pester -Configuration $pesterArgs
# - name: Publish PowerShell test results
# uses: dorny/test-reporter@v1
# with:
# name: PS tests results (${{ matrix.os }})
# path: '**/test-results.xml'
# reporter: jest-junit
- name: Copy files to staging folders
if: ${{ matrix.os == 'windows-latest'}}
shell: pwsh
run: |
Copy-Item -Path "./dist/" -Destination ./staging/VSTeam/dist/ -Recurse -Force
Copy-Item -Path "./.gitignore","./README.md" -Destination ./staging/VSTeam/ -Recurse -Force
Copy-Item -Path "./Tests/SampleFiles/" -Destination ./staging/test/Tests/SampleFiles -Recurse -Force
Copy-Item -Path "./Tests/integration/tests/" -Destination ./staging/test/Tests/integration/tests -Recurse -Force
Copy-Item -Path "./tools/scripts/" -Destination ./staging/tools/scripts -Recurse -Force
Copy-Item -Path "./dist/*.psd1" -Destination ./staging/test/dist -Recurse -Force
- name: Install PSScriptAnalyzer
if: ${{ matrix.os == 'ubuntu-latest'}}
shell: pwsh
run: Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser -Verbose
- name: Run Static Code Analysis
if: ${{ matrix.os == 'ubuntu-latest'}}
shell: pwsh
run: |
$manifest = Import-PowerShellDataFile ./dist/*.psd1
$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 "::error file=$($_.ScriptPath),line=$($_.Line),col=$($_.Column)::$($_.Message)"; $count++ }
if($count -ne 0) { throw "Static Code Analysis with error count = $count" }
- name: Publish Module
if: ${{ matrix.os == 'windows-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: module
path: "./staging/VSTeam"
- name: Publish unit tests
if: ${{ matrix.os == 'windows-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: test
path: "./staging/test"
- name: Publish pipeline scripts
if: ${{ matrix.os == 'windows-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: pipeline-scripts
path: "./staging/tools"
package-stage:
name: Package Management
needs: build-stage
# run from here only if it's not a pull request
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download module
uses: actions/download-artifact@v2
with:
name: module
- name: Download pipeline scripts
uses: actions/download-artifact@v2
with:
name: pipeline-scripts
path: ./tools
- name: Install NuGet 5.2.0
uses: nuget/setup-nuget@v1
with:
nuget-version: '5.2.0'
- name: Install Module Dependencies
shell: pwsh
run: |
./Install-ModuleDependencies -ModulePath "./../../dist"
working-directory: './tools/scripts'
- name: Pack and push module
shell: pwsh
run: |
$version = ./Set-VersionNumber.ps1 -RevisionNumber ${{ github.run_number }} -ModulePath "./../../"
./Invoke-PublishModule.ps1 -GitHubToken $env:GITHUB_TOKEN -Version $version -ModulePath "./../../"
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
working-directory: './tools/scripts'
- name: Upload nuget package as artifact
uses: actions/upload-artifact@v3
with:
name: VSTeamPackage
path: ./dist/*.nupkg
testing-stage:
name: Testing API
needs: package-stage
runs-on: windows-latest
strategy:
matrix:
api_version: [VSTS]
fail-fast: true
steps:
- name: Download nuget package artifact
uses: actions/download-artifact@v2
with:
name: VSTeamPackage
path: ./module
- name: Download integration tests
uses: actions/download-artifact@v2
with:
name: test
path: ./test
- name: Download pipeline scripts
uses: actions/download-artifact@v2
with:
name: pipeline-scripts
path: ./tools
- name: Module test installation
shell: pwsh
run: |
./Test-InstallFromLocalFeed.ps1 -GitHubToken $env:GITHUB_TOKEN -RunnerTempPath '${{ runner.temp }}'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
working-directory: './tools/scripts'
- name: Install Pester
run: Install-Module -Name Pester -Repository PSGallery -Force -AllowPrerelease -MinimumVersion "${{ env.PESTER_VERSION }}" -Scope CurrentUser -AllowClobber -SkipPublisherCheck
shell: pwsh
- name: Run Integration Tests
run: |
Import-Module VSTeam
#This loads [PesterConfiguration] into scope
Import-Module Pester
$pesterArgs = [PesterConfiguration]::Default
$pesterArgs.Run.Exit = $true
$pesterArgs.Run.PassThru = $true
$pesterArgs.Output.Verbosity = "Detailed"
$pesterArgs.TestResult.Enabled = $true
$pesterArgs.TestResult.OutputFormat = 'JUnitXml'
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
$env:VSTEAM_NO_UPDATE_MESSAGE = $true
$env:VSTEAM_NO_MODULE_MESSAGES = $true
Invoke-Pester -Configuration $pesterArgs
shell: pwsh
env:
PAT: ${{ secrets.RSAZDOPAT }}
EMAIL: ${{ secrets.RSEMAIL }}
API_VERSION: ${{ matrix.api_version }}
ACCT: ${{ secrets.RSORG }}
working-directory: './test/Tests/integration'
- name: Prepare test result publishing
run: git init
shell: pwsh
- name: Publish PowerShell test results
uses: dorny/test-reporter@v1
with:
name: PS integration-tests results - (${{ matrix.api_version }})
path: '**/test-results.xml'
reporter: jest-junit
publish-stage:
name: PowerShell Gallery
needs: testing-stage
environment: 'PowerShell Gallery'
runs-on: ubuntu-latest
env:
module_version: ""
steps:
- name: Download PS module artifact
uses: actions/download-artifact@v2
with:
name: module
path: ./module
- name: Download nuget package artifact
uses: actions/download-artifact@v2
with:
name: VSTeamPackage
path: ./nuget
- name: Download pipeline scripts
uses: actions/download-artifact@v2
with:
name: pipeline-scripts
path: ./tools
- name: Install Module Dependencies
shell: pwsh
run: |
./Install-ModuleDependencies.ps1 -ModulePath "../../module/dist"
working-directory: './tools/scripts'
- name: Publish module
shell: pwsh
run: |
$version = ./Set-VersionNumber.ps1 -ModulePath "../../module"
echo "module_version=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
./Invoke-PublishModule.ps1 -PSGalleryApiKey $env:NUGETAPIKEY -ModulePath "../../module"
env:
NUGETAPIKEY: ${{secrets.NUGETAPIKEY}}
working-directory: './tools/scripts'
- uses: ncipollo/release-action@v1
with:
artifacts: 'nuget/*'
artifactErrorsFailBuild: true
allowUpdates: true
commit: trunk
tag: "v${{ env.module_version }}"
discussionCategory: "Announcements"
generateReleaseNotes: true
token: ${{ secrets.GITHUB_TOKEN }}