@@ -31,13 +31,23 @@ jobs:
3131 - name : 📦 Checkout Repository
32323333
34+ - name : 🕵️ Debug Repository Contents
35+ shell : bash
36+ run : |
37+ echo "Current directory: $(pwd)"
38+ echo "Listing all files in repository:"
39+ find . -type f
40+ echo "Checking for PowerShell scripts:"
41+ find . -type f -name "*.ps1" || echo "No .ps1 files found"
42+
3443 - name : 🔎 Run PSScriptAnalyzer and Export SARIF
3544 shell : pwsh
3645 run : |
3746 $ErrorActionPreference = 'Stop'
3847 try {
39- Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
40- Write-Output "PSScriptAnalyzer installed successfully"
48+ Write-Output "Installing PSScriptAnalyzer"
49+ Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -MinimumVersion 1.22.0
50+ Write-Output "PSScriptAnalyzer version: $(Get-Module -ListAvailable PSScriptAnalyzer | Select-Object -ExpandProperty Version)"
4151 $htPSA = @{
4252 Path = '.'
4353 Recurse = $true
@@ -67,19 +77,51 @@ jobs:
6777 }
6878 }
6979 }
70- $htCTS = @{
71- FilePath = './psscriptanalyzer-results.sarif'
72- }
73- Write-Output "Running PSScriptAnalyzer with parameters: $($htPSA | ConvertTo-Json -Depth 5)"
80+ Write-Output "Running PSScriptAnalyzer on path: $(Get-Location)"
7481 $results = Invoke-ScriptAnalyzer @htPSA
82+ $sarifFile = "./psscriptanalyzer-results.sarif"
7583 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"
84+ Write-Output "Found $($results.Count) issues"
85+ # Attempt to use ConvertTo-SARIF if available
86+ if (Get-Command ConvertTo-SARIF -ErrorAction SilentlyContinue) {
87+ $results | ConvertTo-SARIF -FilePath $sarifFile
88+ Write-Output "SARIF file generated using ConvertTo-SARIF: $sarifFile"
89+ } else {
90+ Write-Output "ConvertTo-SARIF not available, generating basic SARIF"
91+ $sarifResults = $results | ForEach-Object {
92+ @{
93+ ruleId = $_.RuleName
94+ level = $_.Severity
95+ message = @{ text = $_.Message }
96+ locations = @(
97+ @{
98+ physicalLocation = @{
99+ artifactLocation = @{ uri = $_.ScriptPath }
100+ region = @{
101+ startLine = $_.Line
102+ startColumn = $_.Column
103+ }
104+ }
105+ }
106+ )
107+ }
108+ }
109+ $sarif = @{
110+ version = "2.1.0"
111+ runs = @(
112+ @{
113+ tool = @{ driver = @{ name = "PSScriptAnalyzer"; version = "$(Get-Module -ListAvailable PSScriptAnalyzer | Select-Object -ExpandProperty Version)" } }
114+ results = $sarifResults
115+ }
116+ )
117+ }
118+ $sarif | ConvertTo-Json -Depth 10 | Out-File -FilePath $sarifFile -Encoding utf8
119+ Write-Output "SARIF file generated manually: $sarifFile"
120+ }
79121 } 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
122+ Write-Output "No issues found or no scripts analyzed"
123+ '{"version": "2.1.0", "runs": []}' | Out-File -FilePath $sarifFile -Encoding utf8
124+ Write-Output "Empty SARIF file generated: $sarifFile"
83125 }
84126 } catch {
85127 Write-Error "PSScriptAnalyzer failed: $_"
90132 shell : bash
91133 run : |
92134 echo "Current directory: $(pwd)"
135+ echo "Listing files:"
93136 ls -la
94137 if [ -f "./psscriptanalyzer-results.sarif" ]; then
95138 echo "SARIF file exists"
@@ -104,7 +147,7 @@ jobs:
104147 uses : actions/upload-artifact@v4
105148 with :
106149 name : psscriptanalyzer-results
107- path : psscriptanalyzer-results.sarif
150+ path : ./ psscriptanalyzer-results.sarif
108151 retention-days : 7
109152
110153 - name : 📤 Upload SARIF to GitHub
@@ -114,4 +157,3 @@ jobs:
114157 sarif_file : ./psscriptanalyzer-results.sarif
115158 checkout_path : ${{ github.workspace }}
116159 wait-for-processing : true
117-
0 commit comments