Skip to content

Commit c4319be

Browse files
Describe helper operations in native PowerShell help
1 parent 29d8cca commit c4319be

2 files changed

Lines changed: 90 additions & 99 deletions

File tree

‎.github/actions/Document-PSModule/src/helpers/Build-PSModuleDocumentation.ps1‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function Build-PSModuleDocumentation {
22
<#
33
.SYNOPSIS
4-
Builds a module.
4+
Build documentation for a PowerShell module.
55
66
.DESCRIPTION
7-
Builds a module.
7+
Build-PSModuleDocumentation creates Markdown help for exported commands and arranges the pages to match the public source folders.
88
#>
99
[CmdletBinding()]
1010
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
@@ -16,19 +16,19 @@
1616
[Parameter(Mandatory)]
1717
[string] $ModuleName,
1818

19-
# Path to the folder where the modules are located.
19+
# Path to the module source folder.
2020
[Parameter(Mandatory)]
2121
[string] $ModuleSourceFolderPath,
2222

23-
# Path to the folder where the built modules are outputted.
23+
# Path to the folder for the built modules.
2424
[Parameter(Mandatory)]
2525
[string] $ModulesOutputFolderPath,
2626

27-
# Path to the folder where the documentation is outputted.
27+
# Path to the documentation output folder.
2828
[Parameter(Mandatory)]
2929
[string] $DocsOutputFolderPath,
3030

31-
# Show GitHub Step Summary even when all commands succeed.
31+
# Show the GitHub step summary even when all commands succeed.
3232
[Parameter()]
3333
[bool] $ShowSummaryOnSuccess = $false
3434
)
@@ -95,7 +95,7 @@
9595
$hasFailures = $failedCommands.Count -gt 0
9696
$shouldShowSummary = $hasFailures -or $ShowSummaryOnSuccess
9797

98-
# Generate summary if ShowSummaryOnSuccess is enabled
98+
# Show the summary on failure or when ShowSummaryOnSuccess is enabled.
9999
if ($shouldShowSummary) {
100100
$statusIcon = $hasFailures ? '❌' : '✅'
101101
$statusText = $hasFailures ? 'Failed' : 'Succeeded'
@@ -151,7 +151,7 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
151151
Write-Host '::endgroup::'
152152
}
153153

154-
# Fail the task if there were any failures (independent of summary display)
154+
# Fail the task on any command failure, independent of the summary display.
155155
if ($hasFailures) {
156156
Write-Error "Documentation generation failed for $($failedCommands.Count) command(s). See above for details."
157157
exit 1
@@ -205,7 +205,7 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
205205
Write-Host " - $relPath"
206206
Write-Host " Path: $file"
207207

208-
# find the source code file that matches the markdown file
208+
# Find the source file that matches the Markdown file.
209209
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
210210
Write-Host " PS1 path: $scriptPath"
211211
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder).Replace('.ps1', '.md')
@@ -227,9 +227,8 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
227227
# Enumerate the public markdown once and reuse it (no second tree walk).
228228
$publicMarkdownFiles = @(Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -File -Include '*.md')
229229

230-
# Folders that provide an explicit index page. Detected case-insensitively because the runner
231-
# filesystem is case-sensitive. Two index pages that differ only by case (index.md and
232-
# Index.md) are ambiguous, so fail fast instead of silently overwriting one.
230+
# Compare index names without case sensitivity because the runner filesystem is case-sensitive.
231+
# Reject index.md and Index.md in the same folder to prevent an ambiguous section index.
233232
$explicitIndexFolders = [System.Collections.Generic.HashSet[string]]::new()
234233
$indexGroups = $publicMarkdownFiles | Where-Object { $_.Name -ieq 'index.md' } | Group-Object { $_.Directory.FullName }
235234
foreach ($group in $indexGroups) {
@@ -247,14 +246,12 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
247246

248247
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $docsOutputFolder)
249248

250-
# A group's overview page becomes the section landing page (index.md) so the navigation
251-
# shows it when the group is selected, instead of a page nested under the group. Authors
252-
# can either name it after the folder (e.g. Auth/Auth.md) or provide Auth/index.md directly.
249+
# A group's overview becomes index.md so the navigation opens it as the section landing page.
250+
# Authors can use the folder name (Auth/Auth.md) or provide Auth/index.md.
253251
$parentFolder = Split-Path -Path $file.FullName -Parent
254252
$parentFolderName = Split-Path -Path $parentFolder -Leaf
255253
if ($file.Name -ieq 'index.md') {
256-
# Normalize any casing (Index.md/INDEX.md) to index.md so it is treated as the
257-
# section index on case-sensitive filesystems.
254+
# Normalize Index.md/INDEX.md to index.md for section indexes on case-sensitive filesystems.
258255
$docsFilePath = Join-Path -Path (Split-Path -Path $docsFilePath -Parent) -ChildPath 'index.md'
259256
Write-Host ' Section index page detected - publishing as index.md'
260257
} elseif ($file.BaseName -eq $parentFolderName) {

0 commit comments

Comments
 (0)