forked from CyberDrain/CIPP
-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (57 loc) · 2.13 KB
/
Copy pathbackend_psscriptanalyzer.yml
File metadata and controls
57 lines (57 loc) · 2.13 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
---
name: Backend PSScriptAnalyzer
on:
pull_request:
branches:
- main
- dev
paths:
- 'backend/**/*.ps1'
- 'backend/**/*.psm1'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
psscriptanalyzer:
if: github.repository_owner == 'CyberDrain'
name: PSScriptAnalyzer
runs-on: ubuntu-latest
# Checkout and artifact upload only; nothing is written back to the repo.
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
# Analyze the backend, excluding the Pester test tree (backend/Tests/**)
$targets = Get-ChildItem -Path ./backend -Recurse -File -Include '*.ps1', '*.psm1' |
Where-Object { $_.FullName -notmatch '[\\/]backend[\\/]Tests[\\/]' }
$results = foreach ($file in $targets) {
Invoke-ScriptAnalyzer -Path $file.FullName -Severity Error,Warning -ExcludeRule PSAvoidUsingWriteHost
}
if ($results) {
$results | Format-Table -AutoSize
$results | Format-List | Out-File -FilePath psscriptanalyzer-results.txt
$errors = $results | Where-Object { $_.Severity -eq 'Error' }
if ($errors) {
Write-Error "PSScriptAnalyzer found $($errors.Count) error(s). Please fix before merging."
exit 1
} else {
Write-Warning "PSScriptAnalyzer found $($results.Count) warning(s). Review recommended."
}
} else {
Write-Host "PSScriptAnalyzer: no issues found."
}
- name: Upload PSScriptAnalyzer results
if: always()
uses: actions/upload-artifact@v4
with:
name: psscriptanalyzer-results
path: psscriptanalyzer-results.txt
if-no-files-found: ignore