Skip to content

Commit 704f1a0

Browse files
Update psscriptanalyzer-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <luizhamilton.lhr@gmail.com>
1 parent 7fb56f0 commit 704f1a0

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

.github/workflows/psscriptanalyzer-check.yml

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,74 @@ name: Analyze PowerShell Scripts
22

33
on:
44
push:
5+
branches:
6+
- main
7+
- develop
58
paths:
69
- '**/*.ps1'
710
pull_request:
11+
branches:
12+
- main
13+
- develop
814
paths:
915
- '**/*.ps1'
1016
workflow_dispatch:
1117

1218
jobs:
1319
psscriptanalyzer:
14-
name: PowerShell Code Style Check
20+
name: PowerShell Code Quality Check
1521
runs-on: ubuntu-latest
1622

1723
steps:
18-
- name: Checkout Repository
24+
- name: 📦 Checkout Repository
1925
uses: actions/checkout@v4.2.2
2026

21-
- name: Run PSScriptAnalyzer
22-
uses: microsoft/psscriptanalyzer-action@v1
27+
- name: 🛠️ Setup PowerShell
28+
uses: actions/setup-powershell@v1
2329
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

Comments
 (0)