PSScriptAnalyzer #11
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: PSScriptAnalyzer | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| patch: | |
| runs-on: windows-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@main | |
| - name: Run PSScriptAnalyzer | |
| run: | | |
| # Check module for errors | |
| $Results = @(Get-ChildItem -Path src -File -Recurse -Include *.ps1, *.psm1, *.psd1 | Invoke-ScriptAnalyzer) | |
| if ($Results | Where-Object -FilterScript {($_.Severity -eq "Error") -or ($_.Severity -eq "ParseError")}) | |
| { | |
| Write-Verbose -Message "Found script issue" -Verbose | |
| $Results | Where-Object -FilterScript {($_.Severity -eq "Error") -or ($_.Severity -eq "ParseError")} | ForEach-Object -Process { | |
| [PSCustomObject]@{ | |
| Line = $_.Line | |
| Message = $_.Message | |
| Path = $_.ScriptPath | |
| } | |
| } | |
| exit 1 # Exit with a non-zero status to fail the job | |
| } | |
| - name: Check JSONs validity | |
| run: | | |
| # Check JSONs for errors | |
| $JSONs = [Array]::TrueForAll((@(Get-ChildItem -Path Wrapper -File -Recurse -Filter *.json).FullName), | |
| [Predicate[string]]{ | |
| param($JSON) | |
| Test-Json -Path $JSON -ErrorAction Ignore | |
| }) | |
| if (-not $JSONs) | |
| { | |
| Write-Verbose -Message "Found JSON issue" -Verbose | |
| exit 1 # Exit with a non-zero status to fail the job | |
| } |