|
26 | 26 |
|
27 | 27 | # Path to the folder where the documentation is outputted. |
28 | 28 | [Parameter(Mandatory)] |
29 | | - [string] $DocsOutputFolderPath |
| 29 | + [string] $DocsOutputFolderPath, |
| 30 | + |
| 31 | + # Show GitHub Step Summary even when all commands succeed. |
| 32 | + [Parameter()] |
| 33 | + [bool] $ShowSummaryOnSuccess = $false |
30 | 34 | ) |
31 | 35 |
|
32 | 36 | Write-Host "::group::Documenting module [$ModuleName]" |
|
53 | 57 | $commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' } |
54 | 58 |
|
55 | 59 | Write-Host "::group::Build docs - Generating markdown help files for $($commands.Count) commands in [$docsOutputFolder]" |
56 | | - $failedCommands = @() |
| 60 | + $commandResults = [System.Collections.Generic.List[PSObject]]::new() |
57 | 61 | foreach ($command in $commands) { |
58 | 62 | try { |
59 | 63 | Write-Host "$($command.Name)" -NoNewline |
|
67 | 71 | } |
68 | 72 | $null = New-MarkdownCommandHelp @params |
69 | 73 | Write-Host " - $($PSStyle.Foreground.Green)✓$($PSStyle.Reset)" |
| 74 | + $commandResults.Add([PSCustomObject]@{ |
| 75 | + CommandName = $command.Name |
| 76 | + Status = 'Success' |
| 77 | + Error = $null |
| 78 | + ErrorString = $null |
| 79 | + }) |
70 | 80 | } catch { |
71 | 81 | Write-Host " - $($PSStyle.Foreground.Red)✗$($PSStyle.Reset)" |
72 | | - $failedCommands += [PSCustomObject]@{ |
73 | | - CommandName = $command.Name |
74 | | - Error = $_ |
75 | | - ErrorString = $_.ToString() |
76 | | - } |
| 82 | + $commandResults.Add([PSCustomObject]@{ |
| 83 | + CommandName = $command.Name |
| 84 | + Status = 'Failed' |
| 85 | + Error = $_ |
| 86 | + ErrorString = $_.ToString() |
| 87 | + }) |
77 | 88 | Write-Error $_ |
78 | 89 | } |
79 | 90 | } |
| 91 | + Write-Host '::endgroup::' |
80 | 92 |
|
81 | | - # If there were failures, generate a summary and fail the task |
82 | | - if ($failedCommands.Count -gt 0) { |
83 | | - Write-Host '::endgroup::' |
84 | | - Write-Host '::group::Build docs - Failed commands summary' |
85 | | - Write-Host "$($PSStyle.Foreground.Red)Failed to generate documentation for $($failedCommands.Count) command(s):$($PSStyle.Reset)" |
86 | | - foreach ($failed in $failedCommands) { |
87 | | - Write-Host " $($PSStyle.Foreground.Red)✗$($PSStyle.Reset) $($failed.CommandName)" |
88 | | - Write-Host " Error: $($failed.ErrorString)" -ForegroundColor Red |
89 | | - } |
90 | | - |
91 | | - $summaryContent = @" |
92 | | -# :x: Documentation Build Failed |
| 93 | + $failedCommands = $commandResults | Where-Object { $_.Status -eq 'Failed' } |
| 94 | + $successfulCommands = $commandResults | Where-Object { $_.Status -eq 'Success' } |
| 95 | + $hasFailures = $failedCommands.Count -gt 0 |
| 96 | + $shouldShowSummary = $hasFailures -or $ShowSummaryOnSuccess |
93 | 97 |
|
94 | | -Failed to generate documentation for **$($failedCommands.Count)** command(s) out of **$($commands.Count)** total. |
| 98 | + # Generate summary if there are failures OR if ShowSummaryOnSuccess is enabled |
| 99 | + if ($shouldShowSummary) { |
| 100 | + $statusIcon = $hasFailures ? '❌' : '✅' |
| 101 | + $statusText = $hasFailures ? 'Failed' : 'Succeeded' |
| 102 | + Write-Host "::group::Build docs - Documentation generation summary $statusIcon" |
95 | 103 |
|
96 | | -## Failed Commands |
| 104 | + $successCount = $successfulCommands.Count |
| 105 | + $failureCount = $failedCommands.Count |
97 | 106 |
|
98 | | -| Command | Error | |
99 | | -|---------|-------| |
100 | | -"@ |
101 | | - foreach ($failed in $failedCommands) { |
102 | | - # Escape pipe characters in error messages for markdown table |
103 | | - $errorMsg = $failed.ErrorString -replace '\|', '\|' -replace "`r`n", '<br>' -replace "`n", '<br>' |
104 | | - $summaryContent += "`n| ``$($failed.CommandName)`` | $errorMsg |" |
105 | | - } |
106 | | - |
107 | | - $summaryContent += @" |
| 107 | + $summaryContent = @" |
| 108 | +# $statusIcon Documentation Build $($statusText.ToLower()) |
108 | 109 |
|
| 110 | +| Success | Failure | |
| 111 | +|---------|---------| |
| 112 | +| $successCount | $failureCount | |
109 | 113 |
|
110 | | -## Summary |
| 114 | +## Command status |
111 | 115 |
|
112 | | -- :white_check_mark: Successful: **$($commands.Count - $failedCommands.Count)** |
113 | | -- :x: Failed: **$($failedCommands.Count)** |
| 116 | +| Command | Status | |
| 117 | +|---------|--------| |
| 118 | +$($commandResults | ForEach-Object { "| ``$($_.CommandName)`` | $($_.Status) |`n" } -join '') |
114 | 119 |
|
115 | 120 | "@ |
116 | | - $summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append |
117 | 121 |
|
| 122 | + $summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append |
118 | 123 | Write-Host '::endgroup::' |
| 124 | + } |
| 125 | + |
| 126 | + # Fail the task if there were any failures (independent of summary display) |
| 127 | + if ($hasFailures) { |
119 | 128 | Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details." |
120 | 129 | exit 1 |
121 | 130 | } |
|
0 commit comments