forked from exercism/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PowerShell script analyzer and CI (exercism#1496)
* ps1 script analyzer and yml ci * analyze and check package * add comments and remove header for pssa
- Loading branch information
1 parent
d4d1489
commit 3e9b727
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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 |