Refactor tests initalization #664
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | |
| } |