-
Notifications
You must be signed in to change notification settings - Fork 120
90 lines (78 loc) · 2.87 KB
/
psscriptanalzyer.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
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
89
90
name: PSScriptAnalyzer
on:
pull_request:
paths:
- "**.ps1"
- "**.psm1"
- "**.psd1"
push:
branches:
- main
- development
- "feature/144-implement-dual-validation-psscriptanalyzer-with-standardized-settings"
paths:
- "**.ps1"
- "**.psm1"
- "**.psd1"
jobs:
analyze:
name: PSScriptAnalyzer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Debug Environment
shell: pwsh
run: |
Write-Host "Current location: $(Get-Location)"
Write-Host "GITHUB_WORKSPACE: $env:GITHUB_WORKSPACE"
Write-Host "Directory contents:"
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse | Select-Object FullName | Format-Table -AutoSize
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
# Debug Paths
Write-Host "Looking for settings file..."
$settingsPath = Join-Path $env:GITHUB_WORKSPACE '.github/psscriptanalyzer/PSScriptAnalyzerSettings.psd1'
Write-Host "Settings path: $settingsPath"
# Check .github folder
$githubPath = Join-Path $env:GITHUB_WORKSPACE '.github'
Write-Host "`n.github folder contents:"
Get-ChildItem -Path $githubPath -Recurse | Select-Object FullName
if (-not (Test-Path $settingsPath)) {
Write-Error "PSScriptAnalyzer settings file not found at: $settingsPath"
exit 1
}
Write-Host "`nFound settings file. Contents:"
Get-Content $settingsPath
$results = @()
Write-Host "`nStarting analysis..."
# Analyze all PowerShell files
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Include *.ps1,*.psm1,*.psd1 |
ForEach-Object {
Write-Host "Analyzing $($_.FullName)"
$analysis = Invoke-ScriptAnalyzer -Path $_.FullName -Settings $settingsPath
if ($analysis) {
$results += $analysis
}
}
if ($results) {
$resultPath = Join-Path $env:GITHUB_WORKSPACE "psscriptanalyzer-results.txt"
$results | Format-Table -AutoSize | Out-File -FilePath $resultPath
$results | Format-Table -AutoSize
Write-Output "::error::PSScriptAnalyzer found $($results.Count) issues"
exit 1
} else {
Write-Output "No PSScriptAnalyzer issues found"
}
- name: Upload PSScriptAnalyzer Results
if: failure()
uses: actions/upload-artifact@v4
with:
name: psscriptanalyzer-results
path: psscriptanalyzer-results.txt
if-no-files-found: warn