1111
1212jobs :
1313 psscriptanalyzer :
14- name : PowerShell Code Quality Check
14+ name : 🧪 PowerShell Code Quality Check
1515 runs-on : ubuntu-latest
1616 permissions :
1717 actions : write
@@ -21,25 +21,27 @@ jobs:
2121
2222 steps :
2323 - name : 📦 Checkout Repository
24- uses : actions/checkout@v4.2.2
24+ uses : actions/checkout@v4
2525
26- - name : 🕵️ Debug Repository Contents
26+ - name : 🔍 Check for PowerShell Files
27+ id : check-ps1
2728 shell : bash
2829 run : |
29- echo "Current directory: $(pwd)"
30- echo "Listing PowerShell scripts:"
31- find . -type f -name "*.ps1"
32- if [ -f ".psscriptanalyzer" ]; then
33- echo ".psscriptanalyzer file found"
34- else
35- echo ".psscriptanalyzer file not found"
30+ count=$(find . -type f -name "*.ps1" | wc -l)
31+ echo "Found $count PowerShell script(s)."
32+ echo "count=$count" >> $GITHUB_OUTPUT
33+ if [ "$count" -eq 0 ]; then
34+ echo "No .ps1 files to analyze. Skipping."
35+ exit 0
3636 fi
3737
3838 - name : 🛠️ Auto-Fix Indentation and Whitespace
3939 shell : pwsh
4040 run : |
4141 $ErrorActionPreference = 'Stop'
42- Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -RequiredVersion 1.24.0
42+ if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
43+ Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -RequiredVersion 1.24.0
44+ }
4345 $htPSA = @{
4446 Path = '.'
4547 Recurse = $true
6466 }
6567 }
6668 Invoke-ScriptAnalyzer @htPSA
67- Write-Output "Auto-fix completed for indentation and whitespace"
69+ Write-Output "Auto-fix completed for indentation and whitespace. "
6870
6971 - name : 📝 Commit Auto-Fixed Files
7072 if : github.event_name == 'push'
7375 git config user.name "GitHub Action"
7476 git config user.email "[email protected] " 7577 git add .
76- git commit -m "Auto-fix PSScriptAnalyzer indentation and whitespace issues" || echo "No changes to commit "
78+ git diff --cached --quiet || git commit -m "Auto-fix PSScriptAnalyzer indentation and whitespace issues"
7779 git push
7880 env :
7981 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8385 run : |
8486 $ErrorActionPreference = 'Stop'
8587 $sarifFile = Join-Path $env:GITHUB_WORKSPACE "psscriptanalyzer-results.sarif"
86- Write-Output "Target SARIF file path: $sarifFile"
87- Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -RequiredVersion 1.24.0
88+ if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
89+ Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser -RequiredVersion 1.24.0
90+ }
8891 $version = (Get-Module -ListAvailable PSScriptAnalyzer)[0].Version.ToString()
8992 Write-Output "PSScriptAnalyzer version: $version"
9093 $htPSA = @{
@@ -122,7 +125,7 @@ jobs:
122125 exit 1
123126 }
124127 if ($results) {
125- Write-Output "Found $($results.Count) issues "
128+ Write-Output "Found $($results.Count) issue(s). "
126129 $sarifResults = $results | ForEach-Object {
127130 @{
128131 ruleId = $_.RuleName
@@ -161,7 +164,7 @@ jobs:
161164 $sarif | ConvertTo-Json -Depth 10 | Out-File -FilePath $sarifFile -Encoding utf8
162165 Write-Output "SARIF file generated: $sarifFile"
163166 } else {
164- Write-Output "No issues found"
167+ Write-Output "No issues found. "
165168 '{"$schema": "http://json.schemastore.org/sarif-2.1.0", "version": "2.1.0", "runs": []}' | Out-File -FilePath $sarifFile -Encoding utf8
166169 }
167170
@@ -180,3 +183,25 @@ jobs:
180183 sarif_file : ${{ github.workspace }}/psscriptanalyzer-results.sarif
181184 checkout_path : ${{ github.workspace }}
182185 wait-for-processing : true
186+
187+ - name : 📝 Generate Markdown Summary
188+ if : always()
189+ shell : pwsh
190+ run : |
191+ $summary = "### 🧪 PowerShell Lint Summary`n"
192+ $sarifPath = Join-Path $env:GITHUB_WORKSPACE "psscriptanalyzer-results.sarif"
193+ if (Test-Path $sarifPath) {
194+ $sarif = Get-Content $sarifPath -Raw | ConvertFrom-Json
195+ $issues = $sarif.runs[0].results
196+ if ($issues.Count -gt 0) {
197+ $summary += "`n**Detected $($issues.Count) issue(s):**`n"
198+ foreach ($i in $issues | Select-Object -First 10) {
199+ $summary += "- [$($i.level)] `$($i.ruleId)`: $($i.message.text)`n"
200+ }
201+ } else {
202+ $summary += "`n✅ No issues found."
203+ }
204+ } else {
205+ $summary += "`n❗ SARIF results not found."
206+ }
207+ $summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
0 commit comments