Skip to content

add better comments for sample output #42

add better comments for sample output

add better comments for sample output #42

name: Lint with PSScriptAnalyzer
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache PowerShell Modules
uses: actions/cache@v2
with:
path: ~/.local/share/powershell/Modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/PSScriptAnalyzer.psd1') }}
restore-keys: |
${{ runner.os }}-modules-
- name: Install PSScriptAnalyzer module
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -Force
- name: Lint with PSScriptAnalyzer
shell: pwsh
run: |
Set-StrictMode -Version Latest
$issues = Invoke-ScriptAnalyzer -Path ./**/*.ps1 -Recurse -ErrorVariable lintErrors
$errors = $issues | Where-Object { $_.Severity -eq 'Error' }
$warnings = $issues | Where-Object { $_.Severity -eq 'Warning' }
$errorCount = ($errors | Measure-Object).Count
$warningCount = ($warnings | Measure-Object).Count
if ($errorCount -gt 0) {
Write-Error "There were $errorCount errors and $warningCount warnings total."
Write-Output "Error Details:"
$errors | Format-List *
exit 1
} elseif ($warningCount -gt 0) {
Write-Output "There were $errorCount errors and $warningCount warnings total."
Write-Output "Warning Details:"
$warnings | Format-List *
} else {
Write-Output "No linting errors or warnings found."
}
- name: Run Pester Tests
shell: pwsh
run: |
Set-StrictMode -Version Latest
Install-Module -Name Pester -Force
Invoke-Pester -Output Detailed