-
Notifications
You must be signed in to change notification settings - Fork 1
257 lines (210 loc) · 8.76 KB
/
ci.yml
File metadata and controls
257 lines (210 loc) · 8.76 KB
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
name: CI
on:
pull_request:
branches: [develop, main]
paths-ignore:
- "docs/**"
- "**/*.md"
- ".vscode/**"
push:
branches: [develop, main]
paths-ignore:
- "docs/**"
- "**/*.md"
- ".vscode/**"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
PSSA_VERSION: "1.24.0"
PESTER_VERSION: "5.7.1"
jobs:
analyze:
name: PSScriptAnalyzer
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Cache PowerShell modules (Linux)
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ~/.local/share/powershell/Modules
key: linux-psmodules-pssa-${{ env.PSSA_VERSION }}
restore-keys: |
linux-psmodules-
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$moduleName = 'PSScriptAnalyzer'
$requiredVersion = [Version]$env:PSSA_VERSION
$installed = Get-Module -ListAvailable -Name $moduleName | Where-Object { $_.Version -eq $requiredVersion }
if (-not $installed) {
Install-Module -Name $moduleName -RequiredVersion $requiredVersion.ToString() -Scope CurrentUser -Force -AllowClobber
}
- name: Run PSScriptAnalyzer (repo policy)
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$settingsPath = Join-Path $PWD 'PSScriptAnalyzerSettings.psd1'
if (-not (Test-Path $settingsPath)) { throw "Settings file not found at $settingsPath" }
$targets = @(
'modules'
'scripts'
'automation/runbooks'
) | Where-Object { Test-Path $_ }
if (-not $targets) {
Write-Host "No analyzer targets found; skipping."
exit 0
}
$results = foreach ($t in $targets) {
Invoke-ScriptAnalyzer -Path $t -Recurse -Settings $settingsPath
}
if ($results) {
$results | Format-Table RuleName, Severity, ScriptName, Line, Message -AutoSize
throw "PSScriptAnalyzer found $($results.Count) issue(s)."
}
test_ps51:
name: Pester (Windows PowerShell 5.1)
runs-on: windows-2022
timeout-minutes: 20
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Cache PowerShell modules (Windows)
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ~\Documents\PowerShell\Modules
key: windows-psmodules-pester-${{ env.PESTER_VERSION }}
restore-keys: |
windows-psmodules-
- name: Install Pester
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$moduleName = 'Pester'
$requiredVersion = [Version]$env:PESTER_VERSION
$installed = Get-Module -ListAvailable -Name $moduleName | Where-Object { $_.Version -eq $requiredVersion }
if (-not $installed) {
Install-Module -Name $moduleName -RequiredVersion $requiredVersion.ToString() -Scope CurrentUser -Force -AllowClobber
}
- name: Run Pester
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$resultsPath = Join-Path $env:GITHUB_WORKSPACE 'Output\TestResults'
New-Item -ItemType Directory -Path $resultsPath -Force | Out-Null
$outFile = Join-Path $resultsPath 'PesterResults_WindowsPowerShell-5.1.xml'
Import-Module Pester -RequiredVersion $env:PESTER_VERSION -Force
$paths = @()
# Module tests: modules/**/Tests
$moduleTests = Get-ChildItem -Path 'modules' -Directory -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq 'Tests' } |
ForEach-Object { $_.FullName }
if ($moduleTests) { $paths += $moduleTests }
# Script tests: scripts/**/Tests
$scriptTests = Get-ChildItem -Path 'scripts' -Directory -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq 'Tests' } |
ForEach-Object { $_.FullName }
if ($scriptTests) { $paths += $scriptTests }
if (-not $paths) {
Write-Host 'No Pester tests found (modules/**/Tests or scripts/**/Tests). Skipping.'
exit 0
}
$config = [PesterConfiguration]::Default
$config.Run.Path = $paths
$config.Run.PassThru = $true
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'JUnitXml'
$config.TestResult.OutputPath = $outFile
$result = Invoke-Pester -Configuration $config
if ($result.FailedCount -gt 0) { throw "Pester failures: $($result.FailedCount)" }
- name: Upload test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: pester-results-windows-ps51
path: Output/TestResults/*.xml
retention-days: 14
if-no-files-found: warn
test_pwsh7:
name: Pester (PowerShell 7)
runs-on: windows-2022
timeout-minutes: 20
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Cache PowerShell modules (Windows)
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ~\Documents\PowerShell\Modules
key: windows-psmodules-pester-${{ env.PESTER_VERSION }}
restore-keys: |
windows-psmodules-
- name: Install Pester
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$moduleName = 'Pester'
$requiredVersion = [Version]$env:PESTER_VERSION
$installed = Get-Module -ListAvailable -Name $moduleName | Where-Object { $_.Version -eq $requiredVersion }
if (-not $installed) {
Install-Module -Name $moduleName -RequiredVersion $requiredVersion.ToString() -Scope CurrentUser -Force -AllowClobber
}
- name: Run Pester
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$resultsPath = Join-Path $env:GITHUB_WORKSPACE 'Output/TestResults'
New-Item -ItemType Directory -Path $resultsPath -Force | Out-Null
$outFile = Join-Path $resultsPath 'PesterResults_PowerShell-7.xml'
Import-Module Pester -RequiredVersion $env:PESTER_VERSION -Force
$paths = @()
# Module tests: modules/**/Tests
$moduleTests = Get-ChildItem -Path 'modules' -Directory -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq 'Tests' } |
ForEach-Object { $_.FullName }
if ($moduleTests) { $paths += $moduleTests }
# Script tests: scripts/**/Tests
$scriptTests = Get-ChildItem -Path 'scripts' -Directory -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq 'Tests' } |
ForEach-Object { $_.FullName }
if ($scriptTests) { $paths += $scriptTests }
if (-not $paths) {
Write-Host 'No Pester tests found (modules/**/Tests or scripts/**/Tests). Skipping.'
exit 0
}
$config = [PesterConfiguration]::Default
$config.Run.Path = $paths
$config.Run.PassThru = $true
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $true
$config.TestResult.OutputFormat = 'JUnitXml'
$config.TestResult.OutputPath = $outFile
$result = Invoke-Pester -Configuration $config
if ($result.FailedCount -gt 0) { throw "Pester failures: $($result.FailedCount)" }
- name: Upload test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: pester-results-windows-pwsh7
path: Output/TestResults/*.xml
retention-days: 14
if-no-files-found: warn