-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathRunPSScriptAnalyzer.ps1
More file actions
49 lines (43 loc) · 1.19 KB
/
RunPSScriptAnalyzer.ps1
File metadata and controls
49 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
param (
[string]$Path,
[string[]]$ExcludeRule,
[switch]$Recurse,
[string]$Output
)
$analyzerModule = Get-Module -ListAvailable -Name PSScriptAnalyzer
if ($null -eq $analyzerModule) {
Install-Module -Name PSScriptAnalyzer -Force
}
$sarifModule = Get-Module -ListAvailable -Name ConvertToSARIF
if ($null -eq $sarifModule) {
Install-Module -Name ConvertToSARIF -Force
}
Import-Module -Name ConvertToSARIF -Force
$htPSA = [ordered]@{ Path = $Path }
if ($ExcludeRule) {
Write-Host "Excluding rules: $ExcludeRule"
$htPSA.add('ExcludeRule', $ExcludeRule)
}
if ($Recurse) {
Write-Host "Recurse: $Recurse"
$htPSA.add('Recurse', $true)
}
$htCTS = [ordered]@{ FilePath = $Output }
$maxRetries = 3
$retryCount = 0
$success = $false
Write-Output "Modules installed, now running tests."
while (-not $success -and $retryCount -lt $maxRetries) {
Try {
Invoke-ScriptAnalyzer @htPSA -Verbose | ConvertTo-SARIF @htCTS
$success = $true
} Catch {
Write-Host "::Error:: $_"
$retryCount++
Write-Output "Retrying... ($retryCount/$maxRetries)"
}
}
if (-not $success) {
Write-Host "::Error:: Failed after $maxRetries attempts."
exit 1
}