Skip to content

Commit d9d4652

Browse files
TestCopilot
andcommitted
feature: add inline test annotations and step summary to CI
Pester failures now emit GitHub Actions workflow commands (::error file=...,line=...) so they appear as inline annotations on the PR Files changed view and Checks tab. A Markdown summary table (pass/fail counts, duration) is written to GITHUB_STEP_SUMMARY and rendered on the run page. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f529828 commit d9d4652

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,53 @@ jobs:
4242
4343
$config = New-PesterConfiguration
4444
$config.Run.Path = './GitSplit.Tests.ps1'
45-
$config.Run.Exit = $true
45+
$config.Run.Exit = $false
46+
$config.Run.PassThru = $true
4647
$config.TestResult.Enabled = $true
4748
$config.Output.Verbosity = 'Detailed'
4849
$config.CodeCoverage.Enabled = $true
4950
$config.CodeCoverage.Path = './GitSplit.psm1'
5051
$config.CodeCoverage.OutputFormat = 'Cobertura'
5152
$config.CodeCoverage.OutputPath = './coverage.cobertura.xml'
5253
53-
Invoke-Pester -Configuration $config
54+
$result = Invoke-Pester -Configuration $config
55+
56+
# GitHub Actions step summary (Markdown rendered on the run page)
57+
$icon = if ($result.FailedCount -eq 0) { '✅' } else { '❌' }
58+
@(
59+
"## $icon Pester Test Results"
60+
''
61+
'| Metric | Count |'
62+
'| --- | --- |'
63+
"| Total | $($result.TotalCount) |"
64+
"| ✅ Passed | $($result.PassedCount) |"
65+
"| ❌ Failed | $($result.FailedCount) |"
66+
"| ⏭️ Skipped | $($result.SkippedCount) |"
67+
"| ⏱️ Duration | $([math]::Round($result.Duration.TotalSeconds, 1))s |"
68+
) | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8
69+
70+
# Inline annotations for failures — surfaces on PR "Files changed" and Checks tab
71+
if ($result.FailedCount -gt 0) {
72+
"" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
73+
"### ❌ Failed tests" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
74+
"" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
75+
foreach ($test in $result.Failed) {
76+
$message = $test.ErrorRecord.Exception.Message -replace '\r?\n', ' '
77+
$file = $test.ScriptBlock.File
78+
$line = $test.ScriptBlock.StartPosition.StartLine
79+
"- **$($test.ExpandedPath)** — $message" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
80+
if ($file -and $line) {
81+
Write-Host "::error file=$file,line=$line::$($test.ExpandedPath): $message"
82+
}
83+
else {
84+
Write-Host "::error::$($test.ExpandedPath): $message"
85+
}
86+
}
87+
}
88+
89+
if ($result.FailedCount -gt 0) {
90+
throw "Pester reported $($result.FailedCount) failing test(s)."
91+
}
5492
5593
- name: Upload coverage
5694
if: always()

0 commit comments

Comments
 (0)