ci: exclude acceptable PSScriptAnalyzer warnings #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| lint: | |
| name: PSScriptAnalyzer | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Run PSScriptAnalyzer | |
| shell: pwsh | |
| run: | | |
| Set-PSRepository PSGallery -InstallationPolicy Trusted | |
| Install-Module PSScriptAnalyzer -Force -Scope CurrentUser | |
| # Exclude rules that are acceptable for interactive console scripts: | |
| # - PSAvoidUsingWriteHost: Intentional for colored console output | |
| # - PSAvoidUsingEmptyCatchBlock: Intentional for silent failure handling | |
| # - PSUseUsingScopeModifierInNewRunspaces: Variables passed via ArgumentList | |
| $excludeRules = @( | |
| 'PSAvoidUsingWriteHost', | |
| 'PSAvoidUsingEmptyCatchBlock', | |
| 'PSUseUsingScopeModifierInNewRunspaces' | |
| ) | |
| $results = Invoke-ScriptAnalyzer -Path ./WinClean.ps1 -Severity Error,Warning -ExcludeRule $excludeRules -ReportSummary | |
| if ($results) { | |
| $results | Format-Table -AutoSize | |
| Write-Host "" | |
| Write-Host "::error::PSScriptAnalyzer found $($results.Count) issue(s)" | |
| exit 1 | |
| } else { | |
| Write-Host "::notice::PSScriptAnalyzer: No issues found!" | |
| } | |
| syntax: | |
| name: Syntax Check | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Check PowerShell syntax | |
| shell: pwsh | |
| run: | | |
| $errors = $null | |
| $ast = [System.Management.Automation.Language.Parser]::ParseFile( | |
| "$PWD/WinClean.ps1", | |
| [ref]$null, | |
| [ref]$errors | |
| ) | |
| if ($errors) { | |
| Write-Host "::error::Syntax errors found:" | |
| $errors | ForEach-Object { Write-Host " - $_" } | |
| exit 1 | |
| } else { | |
| Write-Host "::notice::Syntax check passed!" | |
| } |