forked from jantari/LSUClient
-
Notifications
You must be signed in to change notification settings - Fork 0
45 lines (35 loc) · 1.8 KB
/
PSScriptAnalyzer.yml
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
name: Run PSScriptAnalyzer
on: push
jobs:
PSSA:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install PSScriptAnalyzer Module
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Scope CurrentUser -Repository PSGallery -Force
shell: pwsh -Command "$ProgressPreference = 'SilentlyContinue'; & '{0}'"
- name: Run PSScriptAnalyzer
run: |
Import-Module PSScriptAnalyzer
$PSSAResults = Invoke-ScriptAnalyzer -Path "$ENV:GITHUB_WORKSPACE" -ExcludeRule PSAvoidTrailingWhitespace -Recurse -Verbose
$SUMMARY = ($PSSAResults | Group-Object -Property Severity -NoElement | Foreach-Object { "- $($_.Count) $($_.Name)" }) -join [Environment]::NewLine
$DETAILS = ($PSSAResults | Format-List -Property @{'Name' = 'Location'; 'Expression' = { "{0} [{1}, {2}]" -f (Resolve-Path -LiteralPath $_.ScriptPath -Relative), $_.Line, $_.Column }}, RuleName, Severity, Message | Out-String -Width 88).Trim()
$STRINGBODY = "PSScriptAnalyzer results as of this commit:
$SUMMARY
<details><summary>See details</summary>
``````
$DETAILS
``````
</details>
" | ConvertTo-Json -Compress
$BODY = '"body":{0}' -f $STRINGBODY
Set-Content -LiteralPath 'COMMENTBODY.json' -Value "{$BODY}"
shell: pwsh -Command "$ProgressPreference = 'SilentlyContinue'; & '{0}'"
- name: Add commit comment
run: |
curl -sL --data @COMMENTBODY.json \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments"