-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (99 loc) · 3.11 KB
/
pester-tests.yml
File metadata and controls
114 lines (99 loc) · 3.11 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Pester Tests
on:
push:
branches:
- main
- testing
- test/**
paths:
- "Scripts/**"
- "Tests/**"
- "Modules/**"
- ".github/workflows/pester-tests.yml"
pull_request:
branches:
- main
- testing
paths:
- "Scripts/**"
- "Tests/**"
- "Modules/**"
workflow_dispatch:
permissions:
contents: read
checks: write
pull-requests: write
jobs:
test:
name: Run Pester Tests
runs-on: [self-hosted, linux]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install PowerShell Core
run: |
if ! command -v pwsh &> /dev/null; then
sudo snap install powershell --classic
fi
- name: Verify PowerShell Version
shell: pwsh
run: $PSVersionTable.PSVersion
- name: Install Pester
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Install-Module -Name Pester -RequiredVersion 5.7.1 -Force -SkipPublisherCheck
Get-Module -Name Pester -ListAvailable
- name: Run All Tests
shell: pwsh
run: |
$testPath = 'Tests/'
$resultsFile = 'test-results.xml'
# Get all test files except integration tests
$testFiles = @(Get-ChildItem -Path $testPath -Include '*.Tests.ps1' -Recurse |
Where-Object { $_.FullName -notmatch '(Integration|Network)' })
$pesterConfig = @{
Path = $testFiles
OutputFile = $resultsFile
OutputFormat = 'NUnitXml'
ExcludeTag = @('IntegrationNotImplemented')
PassThru = $true
WarningAction = 'SilentlyContinue'
}
$results = Invoke-Pester @pesterConfig
Write-Host "`n========== Test Summary ==========" -ForegroundColor Cyan
Write-Host "Total Tests: $($results.FailedCount + $results.PassedCount)"
Write-Host "Passed: $($results.PassedCount)" -ForegroundColor Green
Write-Host "Failed: $($results.FailedCount)" -ForegroundColor $(if ($results.FailedCount -gt 0) { 'Red' } else { 'Green' })
Write-Host "=================================" -ForegroundColor Cyan
if ($results.FailedCount -gt 0) {
exit 1
}
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: pester-test-results
path: test-results.xml
retention-days: 30
- name: Publish Test Report
if: always()
uses: EnricoMi/publish-unit-test-result-action/linux@v2
with:
files: test-results.xml
check_name: Test Results (PowerShell)
comment_mode: always
test-summary:
name: Complete Test Suite Summary
runs-on: ubuntu-latest
needs: test
if: always()
steps:
- name: Check Test Results
run: |
if [ "${{ needs.test.result }}" == "failure" ]; then
echo "❌ Tests failed - Build cannot proceed"
exit 1
else
echo "✅ All tests passed successfully"
fi