Skip to content

Fix variable in error log #138

Fix variable in error log

Fix variable in error log #138

name: PSScriptAnalyzer
on:
[pull_request]
jobs:
lint-with-PSScriptAnalyzer:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install required modules
id: InstallPSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
Install-Module FormatMarkdownTable -ErrorAction Stop
- name: Lint with PSScriptAnalyzer
id: RunPSScriptAnalyzer
shell: pwsh
run: |
$ExcludedRules = @('PSAvoidUsingInvokeExpression')
$all = Invoke-ScriptAnalyzer -Path smletsExchangeConnector.ps1 -ExcludeRule $ExcludedRules
$errors = $all.Where({($_.Severity -eq 'Error') -or ($_.Severity -eq 'ParseError')})
$errorCount = $errors.Count
$warnings = $all.Where({$_.Severity -eq 'Warning'})
$warningCount = $warnings.Count
$info = $all.Where({$_.Severity -eq 'Information'})
$infoCount = $info.Count
#Format the Error table
$errors = $errors | Format-MarkdownTableListStyle RuleName, Line, Message
"## :stop_sign: $errorCount Error(s)" >> $env:GITHUB_STEP_SUMMARY
$errors >> $env:GITHUB_STEP_SUMMARY
#Format the Warning table
$warnings = $warnings | Format-MarkdownTableListStyle RuleName, Line, Message
"## :warning: $warningCount Warning(s)" >> $env:GITHUB_STEP_SUMMARY
$warnings >> $env:GITHUB_STEP_SUMMARY
#Format the Info table
$info = $info | Format-MarkdownTableListStyle RuleName, Line, Message
"## :information_source: $infoCount Info" >> $env:GITHUB_STEP_SUMMARY
$info >> $env:GITHUB_STEP_SUMMARY
#either pass or fail
if ($errorCount + $warningCount + $infoCount -ge 1){Write-Error "PSScriptAnalyzer found at least 1 Error, Warning, or Information event. View the Summary for details."; exit 1}
else {exit 0}