Repository navigation
109 lines (98 loc) · 4.02 KB
/
Copy pathci.yml
File metadata and controls
109 lines (98 loc) · 4.02 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
name: CI — Lint & Test
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
lint-and-test:
name: PSScriptAnalyzer + Pester
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -MinimumVersion 1.21.0 -Force -Scope CurrentUser
# NOTE: PSScriptAnalyzer occasionally emits a non-terminating internal
# diagnostic ("Reference Position should begin before start Position of
# Range") that GitHub Actions' default $ErrorActionPreference='Stop'
# promotes to a terminating error. We override to 'Continue' and use
# -ErrorAction SilentlyContinue so the analyzer can finish; real findings
# still appear in $issues and trigger the Count gate below.
- name: Lint — Classes
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
$issues = @(Invoke-ScriptAnalyzer `
-Path LazyWinAdminModule/Classes `
-Recurse `
-Severity Error,Warning `
-Settings LazyWinAdminModule/PSScriptAnalyzerSettings.psd1 `
-ErrorAction SilentlyContinue)
if ($issues.Count -gt 0) {
$issues | Format-Table ScriptName,Line,RuleName,Message -AutoSize -Wrap
throw "$($issues.Count) lint issue(s) in Classes/"
}
- name: Lint — Private functions
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
$issues = @(Invoke-ScriptAnalyzer `
-Path LazyWinAdminModule/Private `
-Recurse `
-Severity Error,Warning `
-Settings LazyWinAdminModule/PSScriptAnalyzerSettings.psd1 `
-ErrorAction SilentlyContinue)
if ($issues.Count -gt 0) {
$issues | Format-Table ScriptName,Line,RuleName,Message -AutoSize -Wrap
throw "$($issues.Count) lint issue(s) in Private/"
}
- name: Lint — Public functions
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
$issues = @(Invoke-ScriptAnalyzer `
-Path LazyWinAdminModule/Public `
-Recurse `
-Severity Error,Warning `
-Settings LazyWinAdminModule/PSScriptAnalyzerSettings.psd1 `
-ErrorAction SilentlyContinue)
if ($issues.Count -gt 0) {
$issues | Format-Table ScriptName,Line,RuleName,Message -AutoSize -Wrap
throw "$($issues.Count) lint issue(s) in Public/"
}
- name: Lint — Test files
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
$issues = @(Invoke-ScriptAnalyzer `
-Path LazyWinAdminModule/Tests `
-Recurse `
-Severity Error,Warning `
-ExcludeRule PSAvoidUsingWriteHost,PSAvoidUsingComputerNameHardcoded,PSReviewUnusedParameter,PSAvoidUsingConvertToSecureStringWithPlainText `
-Settings LazyWinAdminModule/PSScriptAnalyzerSettings.psd1 `
-ErrorAction SilentlyContinue)
if ($issues.Count -gt 0) {
$issues | Format-Table ScriptName,Line,RuleName,Message -AutoSize -Wrap
throw "$($issues.Count) lint issue(s) in Tests/"
}
- name: Install Pester
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Pester -MinimumVersion 5.0.0 -Force -Scope CurrentUser
- name: Run tests
shell: pwsh
run: |
Import-Module Pester -MinimumVersion 5.0.0 -Force
$cfg = New-PesterConfiguration
$cfg.Run.Path = 'LazyWinAdminModule/Tests'
$cfg.Run.PassThru = $true
$cfg.Output.Verbosity = 'Detailed'
$result = Invoke-Pester -Configuration $cfg
if ($result.FailedCount -gt 0) {
throw "$($result.FailedCount) test(s) failed."
}