Repository navigation
129 lines (114 loc) · 4.73 KB
/
Copy pathci.yml
File metadata and controls
129 lines (114 loc) · 4.73 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: CI
on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- '**/*.ps1'
- '.github/workflows/**'
pull_request:
branches: [ master ]
paths:
- '**/*.ps1'
- '.github/workflows/**'
jobs:
test:
strategy:
fail-fast: false
matrix:
include:
# Pester 5.7.1 - Works with all PowerShell versions
- os: windows-2025
name: "Windows Server 2025"
shell: powershell
psVersion: "5.1"
pesterVersion: "5.7.1"
- os: windows-2025
name: "Windows Server 2025"
shell: pwsh
psVersion: "7"
pesterVersion: "5.7.1"
- os: windows-2022
name: "Windows Server 2022"
shell: powershell
psVersion: "5.1"
pesterVersion: "5.7.1"
- os: windows-2022
name: "Windows Server 2022"
shell: pwsh
psVersion: "7"
pesterVersion: "5.7.1"
# Pester 6.0.0 - Requires PowerShell 7.4+ (only on windows-2025 with pwsh)
- os: windows-2025
name: "Windows Server 2025"
shell: pwsh
psVersion: "7"
pesterVersion: "6.0.0"
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }} - PowerShell ${{ matrix.psVersion }} - Pester ${{ matrix.pesterVersion }}
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Cache PowerShell modules
uses: actions/cache@v5
with:
path: ~\Documents\PowerShell\Modules
key: ${{ runner.os }}-ps-${{ matrix.shell }}-pester-${{ matrix.pesterVersion }}
- name: Display OS Information
run: |
Write-Host -Object "Testing on: ${{ matrix.name }}"
Write-Host -Object "Runner OS: ${{ matrix.os }}"
Write-Host -Object "OS Name: $(Get-ComputerInfo -Property WindowsProductName | Select-Object -ExpandProperty WindowsProductName)"
Write-Host -Object "OS Version: $(Get-ComputerInfo -Property WindowsVersion | Select-Object -ExpandProperty WindowsVersion)"
Write-Host -Object "Shell: ${{ matrix.shell }}"
Write-Host -Object "PowerShell Version: $($PSVersionTable.PSVersion)"
- name: Install Pester ${{ matrix.pesterVersion }}
run: |
$module = Get-Module -ListAvailable -Name Pester | Where-Object -FilterScript { $_.Version -eq "${{ matrix.pesterVersion }}" }
if ($module) {
Write-Host -Object "Pester ${{ matrix.pesterVersion }} already installed (from cache)" -ForegroundColor Green
} else {
Write-Host -Object "Installing Pester ${{ matrix.pesterVersion }}..." -ForegroundColor Yellow
Install-Module -Name Pester -RequiredVersion "${{ matrix.pesterVersion }}" -Force -SkipPublisherCheck -AllowClobber
}
Import-Module -Name Pester -RequiredVersion "${{ matrix.pesterVersion }}"
$installedVersion = Get-Module -Name Pester
Write-Host -Object "Pester version: $($installedVersion.Version)" -ForegroundColor Green
- name: Setup PVM
run: |
Write-Host -Object "Setting up PVM..." -ForegroundColor Yellow
.\pvm.bat setup
if ($LASTEXITCODE -ne 0) {
Write-Error -Message "PVM setup failed with exit code: $LASTEXITCODE"
exit $LASTEXITCODE
}
Write-Host -Object "✅ PVM setup completed successfully" -ForegroundColor Green
- name: Debug installed Pester modules
run: Get-Module -ListAvailable -Name Pester | Format-Table Name, Version, ModuleBase
- name: Run tests
run: |
Write-Host -Object "Running PVM tests with Pester ${{ matrix.pesterVersion }}..." -ForegroundColor Yellow
Import-Module -Name Pester -RequiredVersion "${{ matrix.pesterVersion }}"
# Run pvm directly and capture exit code
.\pvm.bat test --coverage=85 --sort=coverage --group=folder --shell="${{ matrix.shell }}" --pester="${{ matrix.pesterVersion }}"
$exitCode = $LASTEXITCODE
Write-Host -Object "Test execution completed with exit code: $exitCode"
if ($exitCode -eq 0) {
Write-Host -Object "✅ All tests passed successfully!" -ForegroundColor Green
} else {
Write-Host -Object "❌ Tests failed with exit code: $exitCode" -ForegroundColor Red
exit $exitCode
}
- name: Dump error log on failure
if: failure()
run: |
$logPath = "storage\logs\error.log"
if (Test-Path -Path $logPath) {
Write-Host -Object "----- error.log -----" -ForegroundColor Red
Get-Content -Path $logPath -Tail 200
} else {
Write-Host -Object "No error.log found at $logPath"
}