From 0fcffb2a62a82e1c934db0d07ba9dd94c5941bd4 Mon Sep 17 00:00:00 2001 From: James Maes Date: Sat, 10 Oct 2026 13:10:40 -0500 Subject: [PATCH] ci: retry PSScriptAnalyzer per file when it throws PSScriptAnalyzer 1.25.0 still throws 'Object reference not set to an instance of an object' intermittently in per-file mode; it blocked the v1.0.2-beta.1 release run until a re-run. Each file is now analyzed up to three times and only a file that keeps throwing fails the gate. Closes #89 Co-Authored-By: Claude Fable 5.1 Signed-off-by: James Maes --- .github/workflows/ci.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 035eaf3..862af75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,13 +169,30 @@ jobs: shell: pwsh run: | Install-Module PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force - # One file per call: PSScriptAnalyzer 1.25.0 intermittently fails with - # "Object reference not set to an instance of an object" when it is - # handed a directory, and never when it is handed a single script. + # One file per call, three attempts each: PSScriptAnalyzer 1.25.0 + # intermittently throws "Object reference not set to an instance of an + # object" from inside the analyzer (#89); a retry has always passed. A + # file that throws three times fails the gate with the analyzer's error. $settings = (Resolve-Path ./PSScriptAnalyzerSettings.psd1).Path $scripts = Get-ChildItem -Path .github/scripts, packaging/chocolatey/tools -Recurse -Include *.ps1, *.psm1, *.psd1 $findings = @() - foreach ($script in $scripts) { $findings += @(Invoke-ScriptAnalyzer -Path $script.FullName -Settings $settings) } + foreach ($script in $scripts) + { + for ($attempt = 1; $attempt -le 3; $attempt++) + { + try + { + $findings += @(Invoke-ScriptAnalyzer -Path $script.FullName -Settings $settings -ErrorAction Stop) + break + } + catch + { + if ($attempt -eq 3) { throw } + Write-Output "::warning file=$($script.FullName)::PSScriptAnalyzer threw on attempt $attempt ($($_.Exception.Message)); retrying." + Start-Sleep -Seconds 2 + } + } + } foreach ($f in $findings) { Write-Output "::error file=$($f.ScriptPath),line=$($f.Line)::$($f.RuleName): $($f.Message)" } if ($findings.Count -gt 0) { exit 1 } Write-Output 'PSScriptAnalyzer: no findings.' -- 2.54.0