@@ -18,52 +18,72 @@ jobs:
18
18
shell : pwsh
19
19
run : |
20
20
Write-Host "Installing required modules..."
21
+
21
22
# Install Pester if needed
22
23
if (-not (Get-Module -ListAvailable -Name Pester)) {
23
24
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
24
25
}
25
26
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
31
30
}
32
31
33
- - name : Run unit tests
32
+ - name : Run PSScriptAnalyzer
34
33
shell : pwsh
35
34
run : |
36
- Write-Host "Running Assert-GenXdevTest ..."
35
+ Write-Host "Running PSScriptAnalyzer ..." -ForegroundColor Cyan
37
36
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
40
40
41
- # Run tests with error handling
42
- try {
43
- $result = Assert-GenXdevTest -Verbosity Detailed -TestFailedAction Stop -SkipModuleImports
41
+ $allFiles = @($scriptFiles) + @($moduleFiles)
42
+ $issuesFound = $false
44
43
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
47
47
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
+ }
53
53
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
+ }
59
58
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
62
65
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
64
70
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
65
79
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"
68
86
exit 1
69
- }
87
+ }
88
+
89
+ Write-Host "`n✓ All Pester tests passed! ($($result.PassedCount) tests)" -ForegroundColor Green
0 commit comments