Skip to content

Commit 925ce64

Browse files
Refactor command output to build HTML tables for missed and executed commands, enhancing readability and consistency in coverage report
1 parent f69b4a2 commit 925ce64

File tree

1 file changed

+94
-45
lines changed

1 file changed

+94
-45
lines changed

scripts/main.ps1

Lines changed: 94 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -135,70 +135,119 @@ LogGroup 'Files analyzed' {
135135
$codeCoverage.FilesAnalyzed | Format-Table -AutoSize | Out-String
136136
}
137137

138-
# --------------------------------------------------------------------------------
139-
# Transform the Command property with markdown code fences before building the table
140-
# --------------------------------------------------------------------------------
141-
$missedForDisplay = $codeCoverage.CommandsMissed | Sort-Object -Property File, Line | ForEach-Object {
142-
$command = (Normalize-IndentationExceptFirst -Code $_.Command)
143-
$command = $command.Replace([Environment]::NewLine, '<br>').Replace(' ', '&nbsp;').Replace('{', '\{').Replace('}', '\}')
144-
$command = '<pre><code class="language-powershell">{0}</pre></code>' -f $command
145-
[PSCustomObject]@{
146-
File = $_.File
147-
Line = $_.Line
148-
StartColumn = $_.StartColumn
149-
EndColumn = $_.EndColumn
150-
Class = $_.Class
151-
Function = $_.Function
152-
# Wrap the command in triple-backtick code fences with "pwsh"
153-
Command = $command
138+
# Build HTML table for 'missed' commands
139+
$tableheader = @'
140+
<table>
141+
<thead>
142+
<tr>
143+
<th>File</th>
144+
<th>Line</th>
145+
<th>StartColumn</th>
146+
<th>EndColumn</th>
147+
<th>Class</th>
148+
<th>Function</th>
149+
<th>Command</th>
150+
</tr>
151+
</thead>
152+
<tbody>
153+
'@
154+
155+
$tablefooter = @'
156+
</tbody>
157+
</table>
158+
159+
'@
160+
161+
LogGroup 'Set table for missed commands' {
162+
$missedForDisplay = $tableheader
163+
164+
foreach ($item in $codeCoverage.CommandsMissed | Sort-Object -Property File, Line) {
165+
$command = [System.Web.HttpUtility]::HtmlEncode($item.Command)
166+
$command = (Normalize-IndentationExceptFirst -Code $_.Command)
167+
$command = $command.Replace([Environment]::NewLine, '<br>').Replace(' ', '&nbsp;').Replace('{', '\{').Replace('}', '\}')
168+
$command = '<pre><code class="language-powershell">{0}</pre></code>' -f $command
169+
$missedForDisplay += @"
170+
<tr>
171+
<td>$($item.File)</td>
172+
<td>$($item.Line)</td>
173+
<td>$($item.StartColumn)</td>
174+
<td>$($item.EndColumn)</td>
175+
<td>$($item.Class)</td>
176+
<td>$($item.Function)</td>
177+
<td>
178+
179+
``````pwsh
180+
$command
181+
``````
182+
183+
</td>
184+
</tr>
185+
186+
"@
154187
}
188+
189+
$missedForDisplay += $tablefooter
155190
}
156191

157-
$executedForDisplay = $codeCoverage.CommandsExecuted | Sort-Object -Property File, Line | ForEach-Object {
158-
$command = (Normalize-IndentationExceptFirst -Code $_.Command)
159-
$command = $command.Replace([Environment]::NewLine, '<br>').Replace(' ', '&nbsp;').Replace('{', '\{').Replace('}', '\}')
160-
$command = '<pre><code class="language-powershell">{0}</pre></code>' -f $command
161-
[PSCustomObject]@{
162-
File = $_.File
163-
Line = $_.Line
164-
StartColumn = $_.StartColumn
165-
EndColumn = $_.EndColumn
166-
Class = $_.Class
167-
Function = $_.Function
168-
# Wrap the command in triple-backtick code fences with "pwsh"
169-
Command = $command
192+
LogGroup 'Set table for executed commands' {
193+
$missedForDisplay = $tableheader
194+
195+
foreach ($item in $codeCoverage.CommandsExecuted | Sort-Object -Property File, Line) {
196+
$command = [System.Web.HttpUtility]::HtmlEncode($item.Command)
197+
$command = (Normalize-IndentationExceptFirst -Code $_.Command)
198+
$command = $command.Replace([Environment]::NewLine, '<br>').Replace(' ', '&nbsp;').Replace('{', '\{').Replace('}', '\}')
199+
$command = '<pre><code class="language-powershell">{0}</pre></code>' -f $command
200+
$missedForDisplay += @"
201+
<tr>
202+
<td>$($item.File)</td>
203+
<td>$($item.Line)</td>
204+
<td>$($item.StartColumn)</td>
205+
<td>$($item.EndColumn)</td>
206+
<td>$($item.Class)</td>
207+
<td>$($item.Function)</td>
208+
<td>
209+
210+
``````pwsh
211+
$command
212+
``````
213+
214+
</td>
215+
</tr>
216+
217+
"@
170218
}
171-
}
172219

173-
# -- Output the markdown to GitHub step summary --
174-
$markdown = Heading 1 'Code Coverage Report' {
220+
$missedForDisplay += $tablefooter
221+
}
175222

176-
Heading 2 'Summary' {
177-
Table {
178-
$stats
179-
}
223+
LogGroup 'Set step summary' {
224+
# -- Output the markdown to GitHub step summary --
225+
$markdown = Heading 1 'Code Coverage Report' {
180226

181-
Details "Missed commands [$($codeCoverage.CommandsMissedCount)]" {
227+
Heading 2 'Summary' {
182228
Table {
229+
$stats
230+
}
231+
232+
Details "Missed commands [$($codeCoverage.CommandsMissedCount)]" {
183233
$missedForDisplay
184234
}
185-
}
186235

187-
Details "Executed commands [$($codeCoverage.CommandsExecutedCount)]" {
188-
Table {
236+
Details "Executed commands [$($codeCoverage.CommandsExecutedCount)]" {
189237
$executedForDisplay
190238
}
191-
}
192239

193-
Details "Files analyzed [$($codeCoverage.FilesAnalyzedCount)]" {
194-
Table {
195-
$codeCoverage | Select-Object -Property FilesAnalyzed
240+
Details "Files analyzed [$($codeCoverage.FilesAnalyzedCount)]" {
241+
Table {
242+
$codeCoverage | Select-Object -Property FilesAnalyzed
243+
}
196244
}
197245
}
198246
}
247+
248+
Set-GitHubStepSummary -Summary $markdown
199249
}
200250

201-
Set-GitHubStepSummary -Summary $markdown
202251

203252
# Throw an error if coverage is below target
204253
if ($coveragePercent -lt $coveragePercentTarget) {

0 commit comments

Comments
 (0)