@@ -18,52 +18,72 @@ jobs:
1818 shell : pwsh
1919 run : |
2020 Write-Host "Installing required modules..."
21+
2122 # Install Pester if needed
2223 if (-not (Get-Module -ListAvailable -Name Pester)) {
2324 Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
2425 }
2526
26- # Import your GenXdev modules
27- $modulePath = "${{ github.workspace }}/Modules"
28- if (Test-Path $modulePath) {
29- $env:PSModulePath = "$modulePath;$env:PSModulePath"
30- Write-Host "Added modules path: $modulePath"
27+ # Install PSScriptAnalyzer if needed
28+ if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
29+ Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
3130 }
3231
33- - name : Run unit tests
32+ - name : Run PSScriptAnalyzer
3433 shell : pwsh
3534 run : |
36- Write-Host "Running Assert-GenXdevTest ..."
35+ Write-Host "Running PSScriptAnalyzer ..." -ForegroundColor Cyan
3736
38- # Import the GenXdev.Coding module which contains Assert-GenXdevTest
39- Import-Module GenXdev.Coding -ErrorAction SilentlyContinue
37+ # Find all .ps1 and .psm1 files in Functions directory
38+ $scriptFiles = Get-ChildItem -Path "${{ github.workspace }}/Functions" -Filter "*.ps1" -Recurse -ErrorAction SilentlyContinue
39+ $moduleFiles = Get-ChildItem -Path "${{ github.workspace }}" -Filter "*.psm1" -Recurse -ErrorAction SilentlyContinue
4040
41- # Run tests with error handling
42- try {
43- $result = Assert-GenXdevTest -Verbosity Detailed -TestFailedAction Stop -SkipModuleImports
41+ $allFiles = @($scriptFiles) + @($moduleFiles)
42+ $issuesFound = $false
4443
45- if (-not $result.Success) {
46- Write-Error "Tests failed!"
44+ foreach ($file in $allFiles) {
45+ Write-Host "`nAnalyzing: $($file.FullName)" -ForegroundColor Yellow
46+ $results = Invoke-ScriptAnalyzer -Path $file.FullName -Severity Warning,Error
4747
48- # Display analyzer results if any
49- if ($result.AnalyzerResults) {
50- Write-Host "`nPSScriptAnalyzer Results:" -ForegroundColor Yellow
51- $result.AnalyzerResults | Format-Table -AutoSize
52- }
48+ if ($ results) {
49+ $issuesFound = $true
50+ $results | Format-Table -AutoSize -Property Severity, Line, RuleName, Message
51+ }
52+ }
5353
54- # Display failed test names if any
55- if ($result.TestResults.Failed) {
56- Write-Host "`nFailed Tests:" -ForegroundColor Red
57- $result.TestResults.Failed.Name | ForEach-Object { Write-Host " - $_" }
58- }
54+ if ($issuesFound) {
55+ Write-Error "PSScriptAnalyzer found issues!"
56+ exit 1
57+ }
5958
60- exit 1
61- }
59+ Write-Host "`n✓ PSScriptAnalyzer passed!" -ForegroundColor Green
60+
61+ - name : Run Pester tests
62+ shell : pwsh
63+ run : |
64+ Write-Host "Running Pester tests..." -ForegroundColor Cyan
6265
63- Write-Host "`n✓ All tests passed!" -ForegroundColor Green
66+ # Check if Tests directory exists
67+ $testsPath = "${{ github.workspace }}/Tests"
68+ if (-not (Test-Path $testsPath)) {
69+ Write-Host "No Tests directory found, skipping Pester tests" -ForegroundColor Yellow
6470 exit 0
71+ }
72+
73+ # Configure Pester
74+ $config = New-PesterConfiguration
75+ $config.Run.Path = $testsPath
76+ $config.Run.PassThru = $true
77+ $config.Output.Verbosity = 'Detailed'
78+ $config.TestResult.Enabled = $false
6579
66- } catch {
67- Write-Error "Error running tests: $($_.Exception.Message)"
80+ # Run tests
81+ $result = Invoke-Pester -Configuration $config
82+
83+ # Check results
84+ if ($result.FailedCount -gt 0) {
85+ Write-Error "Pester tests failed: $($result.FailedCount) test(s) failed"
6886 exit 1
69- }
87+ }
88+
89+ Write-Host "`n✓ All Pester tests passed! ($($result.PassedCount) tests)" -ForegroundColor Green
0 commit comments