Skip to content

Commit 42c533e

Browse files
🌟 [Major]: Introducing Document-PSModule (#16)
## Description ### PR Description This pull request introduces version 1 of `Document-PSModule`, a PowerShell module designed to automate documentation generation. Its main purpose is integration with the existing `Process-PSModule` to automate updates of documentation as processes within modules change. ### What this PR Includes - Structured Documentation: - Defines a clear template for module, function, parameter, and metadata documentation. - Automation Integration: - Provides automatic documentation updates triggered by changes in `Process-PSModule`. ### How it helps Process-PSModule This integration ensures that documentation remains current automatically, reducing manual documentation tasks and keeping documentation consistent with the latest module state. ### Related PR - [Integration PR in Process-PSModule](PSModule/Process-PSModule#150) ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [x] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent a4813bf commit 42c533e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+156
-296
lines changed

.github/workflows/Action-Test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,16 @@ jobs:
2525
- name: Checkout repo
2626
uses: actions/checkout@v4
2727

28-
- name: Initialize environment
29-
uses: PSModule/Initialize-PSModule@main
30-
3128
- name: Upload module artifact
3229
uses: actions/upload-artifact@v4
3330
with:
3431
name: module
35-
path: tests/outputs/modules
32+
path: tests/srcTestRepo/outputs/module
3633
if-no-files-found: error
3734
retention-days: 1
3835

3936
- name: Action-Test
4037
uses: ./
4138
with:
4239
Name: PSModuleTest
43-
Path: tests/src
44-
ModulesOutputPath: tests/outputs/modules
45-
DocsOutputPath: tests/outputs/docs
40+
WorkingDirectory: tests/srcTestRepo

.github/workflows/Auto-Release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@ jobs:
3030

3131
- name: Auto-Release
3232
uses: PSModule/Auto-Release@v1
33-
env:
34-
GITHUB_TOKEN: ${{ github.token }}

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
1-
# Template-Action
1+
# Document-PSModule (by PSModule)
22

3-
A template repository for GitHub Actions
3+
A GitHub Action that automates the generation of documentation for PowerShell modules using Markdown help files.
4+
5+
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the
6+
[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module.
7+
8+
## Details
9+
10+
This action:
11+
- Installs necessary modules, including `platyPS` for documentation generation.
12+
- Loads helper scripts required by the documentation process.
13+
- Generates Markdown documentation from PowerShell module files.
14+
- Ensures Markdown documentation is properly formatted, with correctly tagged PowerShell code blocks.
15+
- Adjusts Markdown file paths to mirror the structure of the source PowerShell module files.
16+
- Outputs organized Markdown documentation suitable for publishing or distribution.
417

518
## Usage
619

20+
Include this action in your workflow to automatically build and structure documentation for your PowerShell module.
21+
722
### Inputs
823

24+
| Input | Description | Required | Default |
25+
|--------------------|-----------------------------------------------|----------|-------------|
26+
| `Name` | Name of the module to document. | No | <Repo name> |
27+
| `WorkingDirectory` | Directory from which the script will execute. | No | `.` |
28+
929
### Secrets
1030

31+
This action does not require any secrets.
32+
1133
### Outputs
1234

35+
This action does not have defined outputs.
36+
1337
### Example
1438

1539
```yaml
16-
Example here
40+
- name: Document PowerShell Module
41+
uses: PSModule/Document-PSModule@v1
42+
with:
43+
Name: 'MyModule'
44+
WorkingDirectory: './module-directory'
1745
```

action.yml

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build-PSModuleDocumentation (by PSModule)
1+
name: Document-PSModule (by PSModule)
22
description: Build documentation for a PowerShell module.
33
author: PSModule
44
branding:
@@ -9,71 +9,22 @@ inputs:
99
Name:
1010
description: Name of the module to process.
1111
required: false
12-
Path:
13-
description: Path to the folder where the modules are located.
12+
WorkingDirectory:
13+
description: The working directory where the script will run from.
1414
required: false
15-
default: src
16-
ModulesOutputPath:
17-
description: Path to the folder where the built modules are outputted.
18-
required: false
19-
default: outputs/modules
20-
DocsOutputPath:
21-
description: Path to the folder where the built docs are outputted.
22-
required: false
23-
default: outputs/docs
24-
ModuleArtifactName:
25-
description: Name of the module artifact to upload.
26-
required: false
27-
default: module
28-
DocsArtifactName:
29-
description: Name of the docs artifact to upload.
30-
required: false
31-
default: docs
32-
Debug:
33-
description: Enable debug output.
34-
required: false
35-
default: 'false'
36-
Verbose:
37-
description: Enable verbose output.
38-
required: false
39-
default: 'false'
40-
Version:
41-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
42-
required: false
43-
Prerelease:
44-
description: Allow prerelease versions if available.
45-
required: false
46-
default: 'false'
15+
default: '.'
4716

4817
runs:
4918
using: composite
5019
steps:
51-
- name: Download module artifact
52-
uses: actions/download-artifact@v4
53-
with:
54-
name: ${{ inputs.ModuleArtifactName }}
55-
path: ${{ inputs.ModulesOutputPath }}
20+
- name: Install-PSModuleHelpers
21+
uses: PSModule/Install-PSModuleHelpers@v1
5622

57-
- name: Run Build-PSModuleDocumentation
58-
uses: PSModule/GitHub-Script@v1
23+
- name: Document-PSModule
24+
shell: pwsh
5925
env:
6026
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
61-
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
62-
GITHUB_ACTION_INPUT_ModulesOutputPath: ${{ inputs.ModulesOutputPath }}
63-
GITHUB_ACTION_INPUT_DocsOutputPath: ${{ inputs.DocsOutputPath }}
64-
with:
65-
Debug: ${{ inputs.Debug }}
66-
Prerelease: ${{ inputs.Prerelease }}
67-
Verbose: ${{ inputs.Verbose }}
68-
Version: ${{ inputs.Version }}
69-
Script: |
70-
# Build-PSModuleDocumentation
71-
${{ github.action_path }}\scripts\main.ps1
72-
73-
- name: Upload docs artifact
74-
uses: actions/upload-artifact@v4
75-
with:
76-
name: ${{ inputs.DocsArtifactName }}
77-
path: ${{ inputs.DocsOutputPath }}
78-
if-no-files-found: error
79-
retention-days: 1
27+
working-directory: ${{ inputs.WorkingDirectory }}
28+
run: |
29+
# Build-PSModuleDocumentation
30+
${{ github.action_path }}/scripts/main.ps1

scripts/helpers/Build-PSModuleDocumentation.ps1

Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@
77
Builds a module.
88
#>
99
[CmdletBinding()]
10-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
11-
'PSReviewUnusedParameter', '', Scope = 'Function',
12-
Justification = 'LogGroup - Scoping affects the variables line of sight.'
13-
)]
1410
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1511
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1612
Justification = 'Want to just write to the console, not the pipeline.'
1713
)]
18-
#Requires -Modules GitHub
19-
#Requires -Modules Utilities
2014
param(
2115
# Name of the module.
2216
[Parameter(Mandatory)]
@@ -35,95 +29,99 @@
3529
[string] $DocsOutputFolderPath
3630
)
3731

38-
LogGroup "Documenting module [$ModuleName]" {
39-
Write-Host "Source path: [$ModuleSourceFolderPath]"
40-
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
41-
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
42-
exit 1
43-
}
44-
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
45-
Write-Host "Module source folder: [$moduleSourceFolder]"
46-
47-
$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
48-
Write-Host "Module output folder: [$moduleOutputFolder]"
32+
Write-Host "::group::Documenting module [$ModuleName]"
33+
[pscustomobject]@{
34+
ModuleName = $ModuleName
35+
ModuleSourceFolderPath = $ModuleSourceFolderPath
36+
ModulesOutputFolderPath = $ModulesOutputFolderPath
37+
DocsOutputFolderPath = $DocsOutputFolderPath
38+
} | Format-List | Out-String
4939

50-
$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force
51-
Write-Host "Docs output folder: [$docsOutputFolder]"
40+
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
41+
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
42+
exit 1
5243
}
44+
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
45+
$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
46+
$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force
5347

54-
LogGroup 'Build docs - Generate markdown help' {
55-
Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent)
56-
$ModuleName | Remove-Module -Force -ErrorAction SilentlyContinue
57-
Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName
58-
Write-Host ($ModuleName | Get-Module)
59-
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
48+
Write-Host '::group::Build docs - Generate markdown help - Raw'
49+
Install-PSModule -Path $ModuleOutputFolder
50+
Write-Host ($ModuleName | Get-Module)
51+
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
52+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
53+
$fileName = $_.Name
54+
Write-Host "::group:: - [$fileName]"
55+
Show-FileContent -Path $_
6056
}
6157

62-
LogGroup 'Build docs - Fix markdown code blocks' {
63-
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
64-
$content = Get-Content -Path $_.FullName
65-
$fixedOpening = $false
66-
$newContent = @()
67-
foreach ($line in $content) {
68-
if ($line -match '^```$' -and -not $fixedOpening) {
69-
$line = $line -replace '^```$', '```powershell'
70-
$fixedOpening = $true
71-
} elseif ($line -match '^```.+$') {
72-
$fixedOpening = $true
73-
} elseif ($line -match '^```$') {
74-
$fixedOpening = $false
75-
}
76-
$newContent += $line
58+
Write-Host '::group::Build docs - Fix markdown code blocks'
59+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
60+
$content = Get-Content -Path $_.FullName
61+
$fixedOpening = $false
62+
$newContent = @()
63+
foreach ($line in $content) {
64+
if ($line -match '^```$' -and -not $fixedOpening) {
65+
$line = $line -replace '^```$', '```powershell'
66+
$fixedOpening = $true
67+
} elseif ($line -match '^```.+$') {
68+
$fixedOpening = $true
69+
} elseif ($line -match '^```$') {
70+
$fixedOpening = $false
7771
}
78-
$newContent | Set-Content -Path $_.FullName
72+
$newContent += $line
7973
}
74+
$newContent | Set-Content -Path $_.FullName
8075
}
8176

82-
LogGroup 'Build docs - Fix markdown escape characters' {
83-
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
84-
$content = Get-Content -Path $_.FullName -Raw
85-
$content = $content -replace '\\`', '`'
86-
$content = $content -replace '\\\[', '['
87-
$content = $content -replace '\\\]', ']'
88-
$content = $content -replace '\\\<', '<'
89-
$content = $content -replace '\\\>', '>'
90-
$content = $content -replace '\\\\', '\'
91-
$content | Set-Content -Path $_.FullName
92-
}
77+
Write-Host '::group::Build docs - Fix markdown escape characters'
78+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
79+
$content = Get-Content -Path $_.FullName -Raw
80+
$content = $content -replace '\\`', '`'
81+
$content = $content -replace '\\\[', '['
82+
$content = $content -replace '\\\]', ']'
83+
$content = $content -replace '\\\<', '<'
84+
$content = $content -replace '\\\>', '>'
85+
$content = $content -replace '\\\\', '\'
86+
$content | Set-Content -Path $_.FullName
9387
}
9488

95-
LogGroup 'Build docs - Structure markdown files to match source files' {
96-
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
97-
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
98-
$file = $_
99-
Write-Host "Processing: $file"
89+
Write-Host '::group::Build docs - Structure markdown files to match source files'
90+
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
91+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
92+
$file = $_
93+
$relPath = [System.IO.Path]::GetRelativePath($DocsOutputFolder.FullName, $file.FullName)
94+
Write-Host " - $relPath"
95+
Write-Host " Path: $file"
10096

101-
# find the source code file that matches the markdown file
102-
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
103-
Write-Host "Found script path: $scriptPath"
104-
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
105-
Write-Host "Doc file path: $docsFilePath"
106-
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
107-
New-Item -Path $docsFolderPath -ItemType Directory -Force
108-
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
109-
}
110-
# Get the MD files that are in the public functions folder and move them to the same place in the docs folder
111-
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
112-
$file = $_
113-
Write-Host "Processing: $file"
114-
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
115-
Write-Host "Doc file path: $docsFilePath"
116-
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
117-
New-Item -Path $docsFolderPath -ItemType Directory -Force
118-
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
119-
}
97+
# find the source code file that matches the markdown file
98+
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
99+
Write-Host " PS1 path: $scriptPath"
100+
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
101+
Write-Host " MD path: $docsFilePath"
102+
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
103+
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
104+
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
120105
}
121106

107+
Write-Host '::group::Build docs - Move markdown files from source files to docs'
108+
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
109+
$file = $_
110+
$relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName)
111+
Write-Host " - $relPath"
112+
Write-Host " Path: $file"
113+
114+
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
115+
Write-Host " MD path: $docsFilePath"
116+
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
117+
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
118+
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
119+
}
120+
121+
Write-Host '────────────────────────────────────────────────────────────────────────────────'
122122
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
123123
$fileName = $_.Name
124-
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
125-
LogGroup " - [$fileName] - [$hash]" {
126-
Show-FileContent -Path $_
127-
}
124+
Write-Host "::group:: - [$fileName]"
125+
Show-FileContent -Path $_
128126
}
129127
}

0 commit comments

Comments
 (0)