@@ -2,24 +2,74 @@ name: Analyze PowerShell Scripts
2
2
3
3
on :
4
4
push :
5
+ branches :
6
+ - main
7
+ - develop
5
8
paths :
6
9
- ' **/*.ps1'
7
10
pull_request :
11
+ branches :
12
+ - main
13
+ - develop
8
14
paths :
9
15
- ' **/*.ps1'
10
16
workflow_dispatch :
11
17
12
18
jobs :
13
19
psscriptanalyzer :
14
- name : PowerShell Code Style Check
20
+ name : PowerShell Code Quality Check
15
21
runs-on : ubuntu-latest
16
22
17
23
steps :
18
- - name : Checkout Repository
24
+ - name : 📦 Checkout Repository
19
25
uses : actions/checkout@v4.2.2
20
26
21
- - name : Run PSScriptAnalyzer
22
- uses : microsoft/psscriptanalyzer-action @v1
27
+ - name : 🛠️ Setup PowerShell
28
+ uses : actions/setup-powershell @v1
23
29
with :
24
- path : ' .'
25
- recurse : true
30
+ powershell-version : ' 7.4'
31
+
32
+ - name : 🧪 Run PSScriptAnalyzer
33
+ run : |
34
+ Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
35
+ $results = Invoke-ScriptAnalyzer -Path . -Recurse -Severity Error, Warning `
36
+ -Settings @{
37
+ IncludeRules = @(
38
+ 'PSAvoidUsingCmdletAliases',
39
+ 'PSUseShouldProcessForStateChangingFunctions',
40
+ 'PSAvoidUsingWriteHost',
41
+ 'PSUseConsistentIndentation',
42
+ 'PSUseConsistentWhitespace'
43
+ )
44
+ Rules = @{
45
+ PSUseConsistentIndentation = @{
46
+ Enable = $true
47
+ IndentationSize = 4
48
+ PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
49
+ }
50
+ PSUseConsistentWhitespace = @{
51
+ Enable = $true
52
+ CheckInnerBrace = $true
53
+ CheckOpenBrace = $true
54
+ CheckOpenParen = $true
55
+ CheckOperator = $true
56
+ CheckSeparator = $true
57
+ }
58
+ }
59
+ }
60
+
61
+ if ($results.Count -gt 0) {
62
+ $results | ConvertTo-Json -Depth 10 | Out-File psscriptanalyzer-results.json
63
+ $results | ForEach-Object { Write-Host "$($_.Severity): $($_.Message) [$($_.RuleName)] in $($_.ScriptName):$($_.Line)" }
64
+ exit 1
65
+ } else {
66
+ Write-Host "✅ No PSScriptAnalyzer violations found."
67
+ }
68
+
69
+ - name : 📊 Upload Analysis Results
70
+ if : always()
71
+ uses : actions/upload-artifact@v4
72
+ with :
73
+ name : psscriptanalyzer-results
74
+ path : psscriptanalyzer-results.json
75
+ retention-days : 7
0 commit comments