-
Notifications
You must be signed in to change notification settings - Fork 7
182 lines (162 loc) · 6.83 KB
/
test.yml
File metadata and controls
182 lines (162 loc) · 6.83 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
name: Run Unit Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PowerShell modules
shell: pwsh
run: |
Write-Host "Installing required modules..."
# Install Pester if needed
if (-not (Get-Module -ListAvailable -Name Pester)) {
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
}
# Install PSScriptAnalyzer if needed
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
}
- name: Create PSScriptAnalyzer settings
shell: pwsh
run: |
$settings = @'
@{
Severity = @('Warning')
IncludeRules = @(
'PSUseFullyQualifiedCmdletNames',
'PSAvoidDefaultValueSwitchParameter',
'PSAvoidUsingCmdletAliases',
'PSAvoidAssignmentToAutomaticVariable',
'PSAvoidDefaultValueForMandatoryParameter',
'PSAvoidExclaimOperator',
'PSAvoidGlobalAliases',
'PSAvoidGlobalFunctions',
'PSAvoidGlobalVars',
'PSAvoidLongLines',
'PSAvoidNullOrEmptyHelpMessageAttribute',
'PSAvoidOverwritingBuiltInCmdlets',
'PSReservedCmdletChar',
'PSReservedParams',
'PSAvoidSemicolonsAsLineTerminators',
'PSAvoidShouldContinueWithoutForce',
'PSAvoidTrailingWhitespace',
'PSAvoidUsingDeprecatedManifestFields',
'PSAvoidUsingDoubleQuotesForConstantString',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSPlaceOpenBrace',
'PSPossibleIncorrectComparisonWithNull',
'PSPossibleIncorrectUsageOfAssignmentOperator',
'PSPossibleIncorrectUsageOfRedirectionOperator',
'PSUseApprovedVerbs',
'PSUseCmdletCorrectly',
'PSUseCompatibleCmdlets',
'PSUseConsistentIndentation',
'PSUseConsistentWhitespace',
'PSUseDeclaredVarsMoreThanAssignments',
'PSUseLiteralInitializerForHashtable',
'PSUseOutputTypeCorrectly',
'PSUseProcessBlockForPipelineCommand',
'PSShouldProcess',
'PSUseShouldProcessForStateChangingFunctions',
'PSUseSingularNouns',
'PSUseSupportsShouldProcess',
'PSUseToExportFieldsInManifest',
'PSUseUsingScopeModifierInNewRunspaces'
)
ExcludeRules = @(
'PSUseCorrectCasing',
'PSUseCompatibleCommands',
'PSAlignAssignmentStatement',
'PSAvoidUsingEmptyCatchBlock',
'PSReviewUnusedParameter',
'PSAvoidInvokingEmptyMembers',
'PSAvoidMultipleTypeAttributes',
'PSAvoidUsingPositionalParameters',
'PSUseBOMForUnicodeEncodedFile',
'PSAvoidUsingUsernameAndPasswordParams',
'PSAvoidUsingAllowUnencryptedAuthentication',
'PSAvoidUsingBrokenHashAlgorithms',
'PSAvoidUsingComputerNameHardcoded',
'PSAvoidUsingConvertToSecureStringWithPlainText',
'PSAvoidUsingInvokeExpression',
'PSAvoidUsingPlainTextForPassword',
'PSAvoidUsingWMICmdlet',
'PSAvoidUsingWriteHost',
'PSUseCompatibleSyntax',
'PSUseCompatibleTypes',
'PSPlaceCloseBrace',
'PSProvideCommentHelp',
'PSUsePSCredentialType',
'PSUseUTF8EncodingForHelpFile',
'PSDSCDscExamplesPresent',
'PSDSCDscTestsPresent',
'PSDSCReturnCorrectTypesForDSCFunctions',
'PSDSCUseIdenticalMandatoryParametersForDSC',
'PSDSCUseIdenticalParametersForDSC',
'PSDSCStandardDSCFunctionsInResource',
'PSDSCUseVerboseMessageInDSCResource'
)
IncludeDefaultRules = $true
RecurseCustomRulePath = $false
Rules = @{
PSUseFullyQualifiedCmdletNames = @{
Enabled = $true
}
}
}
'@
$settings | Out-File -FilePath "${{ github.workspace }}/PSScriptAnalyzerSettings.psd1" -Encoding UTF8
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
Write-Host "Running PSScriptAnalyzer..." -ForegroundColor Cyan
# Find all .ps1 and .psm1 files in Functions directory
$scriptFiles = Get-ChildItem -Path "${{ github.workspace }}/Functions" -Filter "*.ps1" -Recurse -ErrorAction SilentlyContinue
$moduleFiles = Get-ChildItem -Path "${{ github.workspace }}" -Filter "*.psm1" -Recurse -ErrorAction SilentlyContinue
$allFiles = @($scriptFiles) + @($moduleFiles)
$issuesFound = $false
$settingsPath = "${{ github.workspace }}/PSScriptAnalyzerSettings.psd1"
foreach ($file in $allFiles) {
Write-Host "`nAnalyzing: $($file.FullName)" -ForegroundColor Yellow
$results = Invoke-ScriptAnalyzer -Path $file.FullName -Settings $settingsPath
if ($results) {
$issuesFound = $true
$results | Format-Table -AutoSize -Property Severity, Line, RuleName, Message
}
}
if ($issuesFound) {
Write-Error "PSScriptAnalyzer found issues!"
exit 1
}
Write-Host "`n✓ PSScriptAnalyzer passed!" -ForegroundColor Green
- name: Run Pester tests
shell: pwsh
run: |
Write-Host "Running Pester tests..." -ForegroundColor Cyan
# Check if Tests directory exists
$testsPath = "${{ github.workspace }}/Tests"
if (-not (Test-Path $testsPath)) {
Write-Host "No Tests directory found, skipping Pester tests" -ForegroundColor Yellow
exit 0
}
# Configure Pester
$config = New-PesterConfiguration
$config.Run.Path = $testsPath
$config.Run.PassThru = $true
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $false
# Run tests
$result = Invoke-Pester -Configuration $config
# Check results
if ($result.FailedCount -gt 0) {
Write-Error "Pester tests failed: $($result.FailedCount) test(s) failed"
exit 1
}
Write-Host "`n✓ All Pester tests passed! ($($result.PassedCount) tests)" -ForegroundColor Green