Skip to content

Commit

Permalink
PowerShell script analyzer and CI (exercism#1496)
Browse files Browse the repository at this point in the history
* ps1 script analyzer and yml ci

* analyze and check package

* add comments and remove header for pssa
  • Loading branch information
valentin-p authored Feb 11, 2021
1 parent d4d1489 commit 3e9b727
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/pssanalyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Run PSScriptAnalyzer

on: [push, pull_request, workflow_dispatch]

jobs:
analyze:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # 2.3.4
- run: pwsh ./powershell-script-analyzer.ps1
24 changes: 24 additions & 0 deletions powershell-script-analyzer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<#
.SYNOPSIS
Test the PowerShell scripts in the folders.
.DESCRIPTION
Test the PowerShell strict correctness with https://github.com/PowerShell/PSScriptAnalyzer.
.EXAMPLE
The example below will verify all the scripts in the repository
PS C:\> ./powershell-script-analyzer.ps1
#>

# Install PSScriptAnalyzer only if not already available.
if (!(Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Scope CurrentUser -Repository PSGallery -Force
}

Import-Module PSScriptAnalyzer
$PSSAResults = Invoke-ScriptAnalyzer -Path . -ExcludeRule PSAvoidTrailingWhitespace -Recurse
$DETAILS = ($PSSAResults | ForEach-Object { "{0,-11} [{1,-3}, {2,-3}] {3,-50} {4,-35} - {5}" -f $_.Severity, $_.Line, $_.Column, $_.ScriptName, $_.RuleName, $_.Message } | Out-String -Width 88).Trim()
$DETAILS
$SUMMARY = ($PSSAResults | Group-Object -Property Severity -NoElement | Foreach-Object { "$($_.Count) $($_.Name)" }) -join ", "
$SUMMARY

exit $SUMMARY.Count

0 comments on commit 3e9b727

Please sign in to comment.