Skip to content

Commit d1a21e3

Browse files
🩹 [Patch]: Add ShowSummaryOnSuccess input to control summary display in documentation generation
1 parent 0c2e14d commit d1a21e3

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Include this action in your workflow to automatically build and structure docume
2525
|--------------------|-----------------------------------------------|----------|-------------|
2626
| `Name` | Name of the module to document. | No | <Repo name> |
2727
| `WorkingDirectory` | Directory from which the script will execute. | No | `.` |
28+
| `ShowSummaryOnSuccess` | Show GitHub Step Summary even when all commands succeed. | No | `false` |
2829

2930
### Secrets
3031

@@ -42,4 +43,5 @@ This action does not have defined outputs.
4243
with:
4344
Name: 'MyModule'
4445
WorkingDirectory: './module-directory'
46+
ShowSummaryOnSuccess: true # Optional: Show summary even on success
4547
```

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
description: The working directory where the script will run from.
1414
required: false
1515
default: '.'
16+
ShowSummaryOnSuccess:
17+
description: Show GitHub Step Summary even when all commands succeed.
18+
required: false
19+
default: 'false'
1620

1721
runs:
1822
using: composite
@@ -24,6 +28,7 @@ runs:
2428
shell: pwsh
2529
env:
2630
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
31+
GITHUB_ACTION_INPUT_ShowSummaryOnSuccess: ${{ inputs.ShowSummaryOnSuccess }}
2732
working-directory: ${{ inputs.WorkingDirectory }}
2833
run: |
2934
# Build-PSModuleDocumentation

scripts/helpers/Build-PSModuleDocumentation.ps1

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
# Path to the folder where the documentation is outputted.
2828
[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
3034
)
3135

3236
Write-Host "::group::Documenting module [$ModuleName]"
@@ -53,7 +57,7 @@
5357
$commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' }
5458

5559
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()
5761
foreach ($command in $commands) {
5862
try {
5963
Write-Host "$($command.Name)" -NoNewline
@@ -67,55 +71,60 @@
6771
}
6872
$null = New-MarkdownCommandHelp @params
6973
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+
})
7080
} catch {
7181
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+
})
7788
Write-Error $_
7889
}
7990
}
91+
Write-Host '::endgroup::'
8092

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
9397

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"
95103

96-
## Failed Commands
104+
$successCount = $successfulCommands.Count
105+
$failureCount = $failedCommands.Count
97106

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())
108109
110+
| Success | Failure |
111+
|---------|---------|
112+
| $successCount | $failureCount |
109113
110-
## Summary
114+
## Command status
111115
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 '')
114119
115120
"@
116-
$summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
117121

122+
$summaryContent | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
118123
Write-Host '::endgroup::'
124+
}
125+
126+
# Fail the task if there were any failures (independent of summary display)
127+
if ($hasFailures) {
119128
Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details."
120129
exit 1
121130
}

scripts/main.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | Fo
3838
Write-Host '::group::Loading inputs'
3939
$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/'
4040
$moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
41+
$showSummaryOnSuccess = $env:GITHUB_ACTION_INPUT_ShowSummaryOnSuccess -eq 'true'
4142
$moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path
4243
$modulesOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/module'
4344
$docsOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/docs'
@@ -47,6 +48,7 @@ $params = @{
4748
ModuleSourceFolderPath = $moduleSourceFolderPath
4849
ModulesOutputFolderPath = $modulesOutputFolderPath
4950
DocsOutputFolderPath = $docsOutputFolderPath
51+
ShowSummaryOnSuccess = $showSummaryOnSuccess
5052
}
5153

5254
[pscustomobject]$params | Format-List | Out-String

0 commit comments

Comments
 (0)