-
Notifications
You must be signed in to change notification settings - Fork 157
233 lines (205 loc) · 7.44 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
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@v4
- name: Install and cache PowerShell modules
id: psmodulecache
uses: potatoqualitee/psmodulecache@v5.2
with:
modules-to-cache: Pester, PSScriptAnalyzer, SHiPS, Trackyon.Utils, Trackyon.Markdown, Metadata, platyPS
- name: .NET Restore
shell: pwsh
run: dotnet restore --no-cache # have to use no cache of the build will fail on Windows
- name: Build module
shell: pwsh
run: |
if ("${{ matrix.os }}" -eq 'ubuntu-latest') {
./Build-Module.ps1 -configuration Release -buildHelp
} else {
./Build-Module.ps1 -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 = 'None'
$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 == 'ubuntu-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: Run Static Code Analysis
if: ${{ matrix.os == 'ubuntu-latest'}}
shell: pwsh
run: |
Import-PowerShellDataFile ./dist/*.psd1 | Select-Object -ExpandProperty RequiredModules | Import-Module
$r = Invoke-ScriptAnalyzer -Path ./dist -Recurse | Where-Object severity -ne "Information"
$count = 0
$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 == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: module
path: "./staging/VSTeam"
- name: Publish unit tests
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: test
path: "./staging/test"
- name: Publish pipeline scripts
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: pipeline-scripts
path: "./staging/tools"
package-stage:
name: Package
uses: ./.github/workflows/reusable.package.yml
needs: build-stage
secrets:
ghToken: ${{ secrets.GITHUB_TOKEN }}
testing-stage:
name: Testing API
uses: ./.github/workflows/reusable.integration-tests.yml
needs: package-stage
with:
pesterVersion: "5.2.0"
secrets:
ghToken: ${{ secrets.GITHUB_TOKEN }}
publish-stage:
name: PowerShell Gallery
needs: testing-stage
environment: "PowerShell Gallery"
runs-on: ubuntu-latest
steps:
- name: Download PS module artifact
uses: actions/download-artifact@v3
with:
name: module
path: ./module
- name: Download nuget package artifact
uses: actions/download-artifact@v3
with:
name: VSTeamPackage
path: ./nuget
- name: Download pipeline scripts
uses: actions/download-artifact@v3
with:
name: pipeline-scripts
path: ./tools
- name: Get Next Version
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: trunk
- name: Publish module
shell: pwsh
run: |
./Install-ModuleDependencies.ps1 -ModulePath "../../module/dist"
./Invoke-PublishModule.ps1 -PSGalleryApiKey $env:NUGETAPIKEY -ModulePath "../../module"
env:
NUGETAPIKEY: ${{secrets.NUGETAPIKEY}}
working-directory: "./tools/scripts"
- name: Clone repo
uses: actions/checkout@v4
with:
path: "vsteam-repo"
- name: Update Version in PSD1
run: |
if ($null -eq (Get-Module -Name Metadata -ListAvailable)) {
$null = Install-Module -Name Metadata -Scope CurrentUser -Force
}
$path = "vsteam-repo/Source/VSTeam.psd1"
$version = "${{ steps.semver.outputs.next }}"
$manifest = Import-Metadata -Path $path
$manifest.ModuleVersion = $version
$null = Export-Metadata -Path $path -InputObject $manifest
shell: pwsh
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Update VSTeam.psd1 Version to ${{ steps.semver.outputs.next }}"
file_pattern: "vsteam-repo/Source/VSTeam.psd1"
- uses: ncipollo/release-action@v1
with:
name: ${{ steps.semver.outputs.next }}
artifacts: "nuget/*"
makeLatest: true
draft: false
artifactErrorsFailBuild: true
allowUpdates: true
commit: trunk
discussionCategory: "Announcements"
generateReleaseNotes: true
token: ${{ secrets.GITHUB_TOKEN }}