-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathaction.yml
More file actions
88 lines (88 loc) · 3.82 KB
/
action.yml
File metadata and controls
88 lines (88 loc) · 3.82 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: 'Install and run PSScriptAnalyzer'
author: 'Juan Garrido'
description: 'Install and run PSScriptAnalyzer'
branding:
icon: "check-circle"
color: "gray-dark"
inputs:
path:
description: 'Specifies the path to the scripts or module to be analyzed. Wildcard characters are supported.'
required: true
default: '.\'
customRulePath:
description: 'Uses only the custom rules defined in the specified paths to the analysis. To still use the built-in rules, add the -IncludeDefaultRules switch.'
required: false
recurseCustomRulePath:
description: 'Adds rules defined in subdirectories of the CustomRulePath location. By default, Invoke-ScriptAnalyzer uses only the custom rules defined in the specified file or directory. To still use the built-in rules, additionally use the -IncludeDefaultRules switch.'
required: false
excludeRule:
description: 'Omits the specified rules from the Script Analyzer test. Wildcard characters are supported.'
required: false
includeDefaultRules:
description: 'Invoke default rules along with Custom rules.'
required: false
includeRule:
description: 'Runs only the specified rules in the Script Analyzer test. By default, PSScriptAnalyzer runs all rules.'
required: false
severity:
description: 'After running Script Analyzer with all rules, this parameter selects rule violations with the specified severity.'
required: false
recurse:
description: 'Runs Script Analyzer on the files in the Path directory and all subdirectories recursively.'
required: false
suppressedOnly:
description: 'Returns rules that are suppressed, instead of analyzing the files in the path.'
required: false
fix:
description: 'Fixes certain warnings which contain a fix in their DiagnosticRecord.'
required: false
enableExit:
description: 'Exits PowerShell and returns an exit code equal to the number of error records. This can be useful in CI systems.'
required: false
reportSummary:
description: 'Writes a report summary of the found warnings to the host.'
required: false
settings:
description: 'File path that contains user profile or hash table for ScriptAnalyzer.'
required: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
- name: Install PSScriptAnalyzer module
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
$ExcludeDirs = @('pipelines','docs','rules','tests')
$files = Get-ChildItem -Path ${{ inputs.path }} -Recurse | Where-Object {$_.FullName -notmatch ($ExcludeDirs -join '|')}
$ScriptAnalyzer = @{
Config = @{IncludeDefaultRules = $true;}
Rules = Get-ScriptAnalyzerRule
}
$Config = $ScriptAnalyzer.Config
$ScriptAnalyzer.Results = $files | Invoke-ScriptAnalyzer @Config
$errors = $ScriptAnalyzer.Results.Where({($_.Severity -eq 'Error') -or ($_.Severity -eq 'ParseError')})
$warnings = $ScriptAnalyzer.Results.Where({$_.Severity -eq 'Warning'})
$info = $ScriptAnalyzer.Results.Where({$_.Severity -eq 'Information'})
if($errors){
foreach ($e in $errors){
$message = ("file={0},line={1},message{2}" -f $e.ScriptName,$e.Line,$e.Message)
Write-Error -Message $message
}
}
if($warnings){
foreach ($e in $warnings){
$message = ("file={0},line={1},message{2}" -f $e.ScriptName,$e.Line,$e.Message)
Write-Warning -Message $message
}
}
if($info){
foreach ($e in $info){
$message = ("file={0},line={1},message{2}" -f $e.ScriptName,$e.Line,$e.Message)
Write-Warning -Message $message
}
}