Skip to content

Commit 960c7f0

Browse files
Update psscriptanalyzer-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 6827606 commit 960c7f0

1 file changed

Lines changed: 59 additions & 35 deletions

File tree

.github/workflows/psscriptanalyzer-check.yml

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,70 @@ jobs:
3535
shell: pwsh
3636
run: |
3737
$ErrorActionPreference = 'Stop'
38-
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
39-
$htPSA = @{
40-
Path = '.'
41-
Recurse = $true
42-
Severity = @('Error', 'Warning')
43-
IncludeRule = @(
44-
'PSAvoidUsingCmdletAliases',
45-
'PSUseShouldProcessForStateChangingFunctions',
46-
'PSAvoidUsingWriteHost',
47-
'PSUseConsistentIndentation',
48-
'PSUseConsistentWhitespace'
49-
)
50-
Settings = @{
51-
Rules = @{
52-
PSUseConsistentIndentation = @{
53-
Enable = $true
54-
IndentationSize = 4
55-
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
56-
}
57-
PSUseConsistentWhitespace = @{
58-
Enable = $true
59-
CheckInnerBrace = $true
60-
CheckOpenBrace = $true
61-
CheckOpenParen = $true
62-
CheckOperator = $true
63-
CheckSeparator = $true
38+
try {
39+
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
40+
Write-Output "PSScriptAnalyzer installed successfully"
41+
$htPSA = @{
42+
Path = '.'
43+
Recurse = $true
44+
Severity = @('Error', 'Warning')
45+
IncludeRule = @(
46+
'PSAvoidUsingCmdletAliases',
47+
'PSUseShouldProcessForStateChangingFunctions',
48+
'PSAvoidUsingWriteHost',
49+
'PSUseConsistentIndentation',
50+
'PSUseConsistentWhitespace'
51+
)
52+
Settings = @{
53+
Rules = @{
54+
PSUseConsistentIndentation = @{
55+
Enable = $true
56+
IndentationSize = 4
57+
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
58+
}
59+
PSUseConsistentWhitespace = @{
60+
Enable = $true
61+
CheckInnerBrace = $true
62+
CheckOpenBrace = $true
63+
CheckOpenParen = $true
64+
CheckOperator = $true
65+
CheckSeparator = $true
66+
}
6467
}
6568
}
6669
}
67-
}
68-
69-
$htCTS = @{
70-
FilePath = 'psscriptanalyzer-results.sarif'
71-
}
72-
73-
try {
74-
Invoke-ScriptAnalyzer @htPSA | ConvertTo-SARIF @htCTS
70+
$htCTS = @{
71+
FilePath = './psscriptanalyzer-results.sarif'
72+
}
73+
Write-Output "Running PSScriptAnalyzer with parameters: $($htPSA | ConvertTo-Json -Depth 5)"
74+
$results = Invoke-ScriptAnalyzer @htPSA
75+
if ($results) {
76+
Write-Output "Analysis completed. Found $($results.Count) issues."
77+
$results | ConvertTo-SARIF @htCTS
78+
Write-Output "SARIF file generated at: ./psscriptanalyzer-results.sarif"
79+
} else {
80+
Write-Output "No issues found or no scripts analyzed."
81+
# Create an empty SARIF file to avoid upload failure
82+
'{"version": "2.1.0", "runs": []}' | Out-File -FilePath ./psscriptanalyzer-results.sarif -Encoding utf8
83+
}
7584
} catch {
7685
Write-Error "PSScriptAnalyzer failed: $_"
7786
exit 1
7887
}
7988
89+
- name: 🕵️ Debug SARIF File Existence
90+
shell: bash
91+
run: |
92+
echo "Current directory: $(pwd)"
93+
ls -la
94+
if [ -f "./psscriptanalyzer-results.sarif" ]; then
95+
echo "SARIF file exists"
96+
cat ./psscriptanalyzer-results.sarif
97+
else
98+
echo "SARIF file not found"
99+
exit 1
100+
fi
101+
80102
- name: 📊 Upload Analysis Results
81103
if: always()
82104
uses: actions/upload-artifact@v4
@@ -89,5 +111,7 @@ jobs:
89111
if: always()
90112
uses: github/codeql-action/upload-sarif@v3
91113
with:
92-
sarif_file: psscriptanalyzer-results.sarif
114+
sarif_file: ./psscriptanalyzer-results.sarif
115+
checkout_path: ${{ github.workspace }}
116+
wait-for-processing: true
93117

0 commit comments

Comments
 (0)