|
53 | 53 | $commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' } |
54 | 54 |
|
55 | 55 | Write-Host "::group::Build docs - Generating markdown help files for $($commands.Count) commands in [$docsOutputFolder]" |
| 56 | + $failedCommands = @() |
56 | 57 | foreach ($command in $commands) { |
57 | 58 | try { |
58 | 59 | Write-Host "$($command.Name)" -NoNewline |
|
68 | 69 | Write-Host " - $($PSStyle.Foreground.Green)ā$($PSStyle.Reset)" |
69 | 70 | } catch { |
70 | 71 | Write-Host " - $($PSStyle.Foreground.Red)ā$($PSStyle.Reset)" |
71 | | - $_ |
| 72 | + $failedCommands += [PSCustomObject]@{ |
| 73 | + CommandName = $command.Name |
| 74 | + Error = $_ |
| 75 | + ErrorString = $_.ToString() |
| 76 | + } |
| 77 | + Write-Error $_ |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 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 | +
|
| 94 | +Failed to generate documentation for **$($failedCommands.Count)** command(s) out of **$($commands.Count)** total. |
| 95 | +
|
| 96 | +## Failed Commands |
| 97 | +
|
| 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 |" |
72 | 105 | } |
| 106 | + |
| 107 | + $summaryContent += @" |
| 108 | +
|
| 109 | +
|
| 110 | +## Summary |
| 111 | +
|
| 112 | +- :white_check_mark: Successful: **$($commands.Count - $failedCommands.Count)** |
| 113 | +- :x: Failed: **$($failedCommands.Count)** |
| 114 | +
|
| 115 | +"@ |
| 116 | + $summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append |
| 117 | + |
| 118 | + Write-Host '::endgroup::' |
| 119 | + Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details." |
| 120 | + exit 1 |
73 | 121 | } |
74 | 122 |
|
75 | 123 | Write-Host '::group::Build docs - Generated files' |
|
0 commit comments