|
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]" |
| 60 | + $commandResults = [System.Collections.Generic.List[PSObject]]::new() |
56 | 61 | foreach ($command in $commands) { |
57 | 62 | try { |
58 | 63 | Write-Host "$($command.Name)" -NoNewline |
|
66 | 71 | } |
67 | 72 | $null = New-MarkdownCommandHelp @params |
68 | 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 | + }) |
69 | 80 | } catch { |
70 | 81 | Write-Host " - $($PSStyle.Foreground.Red)✗$($PSStyle.Reset)" |
71 | | - $_ |
| 82 | + $commandResults.Add([PSCustomObject]@{ |
| 83 | + CommandName = $command.Name |
| 84 | + Status = 'Failed' |
| 85 | + Error = $_ |
| 86 | + ErrorString = $_.ToString() |
| 87 | + }) |
| 88 | + Write-Error $_ |
72 | 89 | } |
73 | 90 | } |
| 91 | + Write-Host '::endgroup::' |
| 92 | + |
| 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 |
| 97 | + |
| 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" |
| 103 | + |
| 104 | + $successCount = $successfulCommands.Count |
| 105 | + $failureCount = $failedCommands.Count |
| 106 | + |
| 107 | + $summaryContent = @" |
| 108 | +# $statusIcon Documentation Build $($statusText.ToLower()) |
| 109 | +
|
| 110 | +| Success | Failure | |
| 111 | +|---------|---------| |
| 112 | +| $successCount | $failureCount | |
| 113 | +
|
| 114 | +## Command status |
| 115 | +
|
| 116 | +| Command | Status | |
| 117 | +|---------|--------| |
| 118 | +$(($commandResults | ForEach-Object { "| ``$($_.CommandName)`` | $($_.Status) |`n" }) -join '') |
| 119 | +
|
| 120 | +"@ |
| 121 | + |
| 122 | + |
| 123 | + $summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append |
| 124 | + Write-Host "$summaryContent" |
| 125 | + Write-Host '::endgroup::' |
| 126 | + } |
| 127 | + |
| 128 | + # Fail the task if there were any failures (independent of summary display) |
| 129 | + if ($hasFailures) { |
| 130 | + Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details." |
| 131 | + exit 1 |
| 132 | + } |
74 | 133 |
|
75 | 134 | Write-Host '::group::Build docs - Generated files' |
76 | 135 | Get-ChildItem -Path $docsOutputFolder -Recurse | Select-Object -ExpandProperty FullName |
|
0 commit comments