Skip to content

Commit 71c21f4

Browse files
🩹 [Patch]: Update to use Microsoft.PowerShell.PlatyPS for docs generation (#19)
## Description This pull request introduces several improvements to the documentation generation process, CI workflows, and PowerShell module metadata. The most significant changes include enhanced and more robust documentation generation, updates to GitHub Actions workflows for better security and linting, and improvements to module help comments for consistency. **Documentation generation improvements:** * The `Build-PSModuleDocumentation.ps1` script now generates markdown help per command, handles documentation file organization to match source structure, and fixes frontmatter titles for compatibility. This makes the documentation process more robust and the output more consistent. [[1]](diffhunk://#diff-95b236851bd9052577a2cdf569f08e195e7d6cc424f6cb6d074ccc10b2cb7241L50-R75) [[2]](diffhunk://#diff-95b236851bd9052577a2cdf569f08e195e7d6cc424f6cb6d074ccc10b2cb7241L91-R148) * The script now uses the full module name `Microsoft.PowerShell.PlatyPS` for installation, ensuring compatibility. **GitHub Actions workflow enhancements:** * The `Action-Test.yml` workflow now requests explicit permissions for reading contents and writing statuses, uses a full-depth fetch for checkouts, logs file changes, commits documentation updates, and adds a markdown linter step. [[1]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L18-R20) [[2]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R29-R31) [[3]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R46-R63) * The `Linter.yml` workflow disables certain linters for performance and disables credential persistence for increased security. [[1]](diffhunk://#diff-482e65806ed9e4a7320f14964764086b91fed4a28d12e4efde1776472e147e79R24) [[2]](diffhunk://#diff-482e65806ed9e4a7320f14964764086b91fed4a28d12e4efde1776472e147e79R34-R35) **PowerShell module metadata improvements:** * Added `.DESCRIPTION` sections to all module functions for better help output, and added `.NOTES` with control instructions to `Set-PSModuleTest` and its corresponding public function. [[1]](diffhunk://#diff-b6253bdc18cdabe21d009dc3778e7ef0d84effe3d28242d670a938b0f710920cR259-R261) [[2]](diffhunk://#diff-b6253bdc18cdabe21d009dc3778e7ef0d84effe3d28242d670a938b0f710920cR288-R290) [[3]](diffhunk://#diff-b6253bdc18cdabe21d009dc3778e7ef0d84effe3d28242d670a938b0f710920cR319-R331) [[4]](diffhunk://#diff-b6253bdc18cdabe21d009dc3778e7ef0d84effe3d28242d670a938b0f710920cR356-R358) [[5]](diffhunk://#diff-1d4bb1ca6780e5c612c9b2db51bb1c07c381ef6608cd52a7780ec786ad6946cdR10-R15) Link: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.platyps/new-markdowncommandhelp?view=ps-modules
1 parent e9f43e3 commit 71c21f4

File tree

6 files changed

+92
-8
lines changed

6 files changed

+92
-8
lines changed

‎.github/workflows/Action-Test.yml‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
1616
cancel-in-progress: true
1717

18-
permissions: {}
18+
permissions:
19+
contents: read # to checkout the repo
20+
statuses: write # to create commit status
1921

2022
jobs:
2123
ActionTestDefault:
@@ -24,6 +26,9 @@ jobs:
2426
steps:
2527
- name: Checkout repo
2628
uses: actions/checkout@v5
29+
with:
30+
persist-credentials: false
31+
fetch-depth: 0
2732

2833
- name: Upload module artifact
2934
uses: actions/upload-artifact@v4
@@ -38,3 +43,21 @@ jobs:
3843
with:
3944
Name: PSModuleTest
4045
WorkingDirectory: tests/srcTestRepo
46+
47+
- name: Get changes
48+
uses: PSModule/GitHub-Script@v1
49+
with:
50+
Script: |
51+
LogGroup "List files" {
52+
Get-ChildItem -Recurse -File | Select-Object -ExpandProperty FullName | Sort-Object
53+
}
54+
LogGroup "Commit changes" {
55+
git add tests/srcTestRepo/outputs/docs/
56+
git commit -m "Update documentation"
57+
}
58+
59+
- name: Lint documentation
60+
uses: super-linter/super-linter/slim@7bba2eeb89d01dc9bfd93c497477a57e72c83240 # v8.2.0
61+
env:
62+
GITHUB_TOKEN: ${{ github.token }}
63+
VALIDATE_MARKDOWN: true

‎.github/workflows/Linter.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- name: Checkout repo
2222
uses: actions/checkout@v5
2323
with:
24+
persist-credentials: false
2425
fetch-depth: 0
2526

2627
- name: Lint code base
@@ -30,3 +31,5 @@ jobs:
3031
VALIDATE_JSON_PRETTIER: false
3132
VALIDATE_MARKDOWN_PRETTIER: false
3233
VALIDATE_YAML_PRETTIER: false
34+
VALIDATE_BIOME_FORMAT: false
35+
VALIDATE_GITHUB_ACTIONS_ZIZMOR: false

‎scripts/helpers/Build-PSModuleDocumentation.ps1‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,32 @@
4747

4848
Write-Host '::group::Build docs - Generate markdown help - Raw'
4949
Install-PSModule -Path $ModuleOutputFolder
50-
Write-Host ($ModuleName | Get-Module)
51-
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
50+
$moduleInfo = Import-Module -Name $ModuleName -Force -PassThru
51+
52+
# Get all exported commands from the module
53+
$commands = $moduleInfo.ExportedCommands.Values | Where-Object { $_.CommandType -ne 'Alias' }
54+
55+
Write-Host "Found $($commands.Count) commands to process"
56+
57+
foreach ($command in $commands) {
58+
try {
59+
Write-Host "$($command.Name)" -NoNewline
60+
$params = @{
61+
CommandInfo = $command
62+
OutputFolder = $docsOutputFolder
63+
Encoding = 'utf8'
64+
ProgressAction = 'SilentlyContinue'
65+
ErrorAction = 'Stop'
66+
Force = $true
67+
}
68+
$null = New-MarkdownCommandHelp @params
69+
Write-Host ' - ✓' -ForegroundColor Green
70+
} catch {
71+
Write-Host ' - ✗' -ForegroundColor Red
72+
$_
73+
}
74+
}
75+
5276
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
5377
$fileName = $_.Name
5478
Write-Host "::group:: - [$fileName]"
@@ -88,30 +112,40 @@
88112

89113
Write-Host '::group::Build docs - Structure markdown files to match source files'
90114
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
91-
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
115+
$moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName
116+
Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
92117
$file = $_
93-
$relPath = [System.IO.Path]::GetRelativePath($DocsOutputFolder.FullName, $file.FullName)
118+
$relPath = [System.IO.Path]::GetRelativePath($moduleDocsFolder, $file.FullName)
94119
Write-Host " - $relPath"
95120
Write-Host " Path: $file"
96121

97122
# find the source code file that matches the markdown file
98123
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
99124
Write-Host " PS1 path: $scriptPath"
100-
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
125+
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder).Replace('.ps1', '.md')
101126
Write-Host " MD path: $docsFilePath"
102127
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
103128
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
104129
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
105130
}
106131

132+
Write-Host '::group::Build docs - Fix frontmatter title'
133+
Get-ChildItem -Path $moduleDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
134+
$content = Get-Content -Path $_.FullName -Raw
135+
# Replace 'title:' with 'ms.title:' in frontmatter only (between --- markers)
136+
$content = $content -replace '(?s)^(---.*?)title:(.*?---)', '$1ms.title:$2'
137+
$content | Set-Content -Path $_.FullName
138+
}
139+
107140
Write-Host '::group::Build docs - Move markdown files from source files to docs'
141+
$moduleDocsFolder = Join-Path $DocsOutputFolder.FullName $ModuleName
108142
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
109143
$file = $_
110144
$relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName)
111145
Write-Host " - $relPath"
112146
Write-Host " Path: $file"
113147

114-
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
148+
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $moduleDocsFolder)
115149
Write-Host " MD path: $docsFilePath"
116150
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
117151
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force

‎scripts/main.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param()
77

88
$PSStyle.OutputRendering = 'Ansi'
99

10-
'platyPS' | ForEach-Object {
10+
'Microsoft.PowerShell.PlatyPS' | ForEach-Object {
1111
$name = $_
1212
Write-Output "Installing module: $name"
1313
$retryCount = 5

‎tests/srcTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ function Get-PSModuleTest {
256256
.SYNOPSIS
257257
Performs tests on a module.
258258
259+
.DESCRIPTION
260+
Performs tests on a module.
261+
259262
.EXAMPLE
260263
Test-PSModule -Name 'World'
261264
@@ -282,6 +285,9 @@ function New-PSModuleTest {
282285
.SYNOPSIS
283286
Performs tests on a module.
284287
288+
.DESCRIPTION
289+
Performs tests on a module.
290+
285291
.EXAMPLE
286292
Test-PSModule -Name 'World'
287293
@@ -310,10 +316,19 @@ function Set-PSModuleTest {
310316
.SYNOPSIS
311317
Performs tests on a module.
312318
319+
.DESCRIPTION
320+
Performs tests on a module.
321+
313322
.EXAMPLE
314323
Test-PSModule -Name 'World'
315324
316325
"Hello, World!"
326+
327+
.NOTES
328+
Controls:
329+
- :q : Quit
330+
- :q! : Quit without saving
331+
- :wq : Save and quit
317332
#>
318333
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
319334
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
@@ -338,6 +353,9 @@ function Test-PSModuleTest {
338353
.SYNOPSIS
339354
Performs tests on a module.
340355
356+
.DESCRIPTION
357+
Performs tests on a module.
358+
341359
.EXAMPLE
342360
Test-PSModule -Name 'World'
343361

‎tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
Test-PSModule -Name 'World'
88
99
"Hello, World!"
10+
11+
.NOTES
12+
Controls:
13+
- :q : Quit
14+
- :q! : Quit without saving
15+
- :wq : Save and quit
1016
#>
1117
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1218
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',

0 commit comments

Comments
 (0)