Skip to content

🌟 [Major]: Introducing Document-PSModule #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5590760
Rename action and enhance documentation build process
MariusStorhaug Feb 16, 2025
140d9dd
Enhance action.yml by adding DocsOutputPath and SiteOutputPath inputs
MariusStorhaug Feb 16, 2025
486091a
Add JSCPD validation option to action.yml
MariusStorhaug Feb 16, 2025
d9e3d1c
Refactor action.yml by removing unused inputs and streamlining the do…
MariusStorhaug Feb 16, 2025
ede26e4
Refactor action.yml by removing the ModuleArtifactName input and rela…
MariusStorhaug Feb 16, 2025
5fe14db
Refactor module import and removal logic in PowerShell scripts to imp…
MariusStorhaug Feb 20, 2025
abcaf67
Add initial implementation of PSModule with supporting files and conf…
MariusStorhaug Feb 24, 2025
511d288
Add configuration and type definition files for PSModuleTest; remove …
MariusStorhaug Feb 24, 2025
ebc8549
Refactor main.ps1 to streamline module source and output path definit…
MariusStorhaug Feb 24, 2025
62cfad3
Refactor main.ps1 to use Resolve-Path for module source and output fo…
MariusStorhaug Feb 24, 2025
6ead217
Refactor main.ps1 to use Join-Path for constructing folder paths, enh…
MariusStorhaug Feb 24, 2025
593f698
Fix Remove-PSModule.ps1 to use Get-PSResource instead of Get-Installe…
MariusStorhaug Feb 24, 2025
71cb072
Enhance Remove-PSModule.ps1 to improve module and command removal pro…
MariusStorhaug Feb 24, 2025
dfc6375
Update action.yml and main.ps1 to clarify module path input and enhan…
MariusStorhaug Feb 24, 2025
9fbde31
Add logging for module source and output paths in main.ps1 for better…
MariusStorhaug Feb 24, 2025
87bc22e
Refactor scripts to improve readability and maintainability; add Add-…
MariusStorhaug Feb 26, 2025
2c0a967
Refactor action.yml and Build-PSModuleDocumentation.ps1 to streamline…
MariusStorhaug Feb 26, 2025
da8dadb
Remove dependency on PSModule/GitHub-Script in action.yml to simplify…
MariusStorhaug Feb 26, 2025
d682b93
Enhance error handling in Remove-PSModule.ps1 by adding -ErrorAction …
MariusStorhaug Feb 26, 2025
ab4de46
Remove Add-PSModulePath and Remove-PSModule functions to simplify mod…
MariusStorhaug Feb 26, 2025
fc58cca
Refactor Resolve-PSModuleDependency to support Install-PSResource and…
MariusStorhaug Feb 26, 2025
dccdd8f
Refactor Resolve-PSModuleDependency to simplify installation parameters
MariusStorhaug Feb 26, 2025
48672a6
Add TrustRepository parameter to installation parameters in Resolve-P…
MariusStorhaug Feb 26, 2025
f811cca
Refactor Resolve-PSModuleDependency to enhance version handling and i…
MariusStorhaug Feb 26, 2025
7daac2e
Refactor Import-PSModule to validate module existence using imported …
MariusStorhaug Feb 26, 2025
bd73f91
Add installation and import of modules from platyPS with TrustReposit…
MariusStorhaug Feb 26, 2025
d275933
Refactor action.yml and main.ps1 to remove Path input and add Working…
MariusStorhaug Feb 28, 2025
7ab55c4
Update Action-Test.yml to replace Path input with WorkingDirectory fo…
MariusStorhaug Feb 28, 2025
924f8bf
Refactor main.ps1 to use Resolve-Path for output folder paths, improv…
MariusStorhaug Feb 28, 2025
f93eb7c
Refactor main.ps1 to replace Resolve-Path with Join-Path for output f…
MariusStorhaug Feb 28, 2025
982e70c
Update action.yml and Import-PSModule.ps1 to enhance output formattin…
MariusStorhaug Mar 2, 2025
5df55a7
Refactor Build-PSModuleDocumentation.ps1 and main.ps1 to enhance outp…
MariusStorhaug Mar 2, 2025
98f0b8b
Refactor Build-PSModuleDocumentation.ps1 to improve output clarity; r…
MariusStorhaug Mar 2, 2025
d7a1d5d
Refactor Build-PSModuleDocumentation.ps1 to enhance output formatting…
MariusStorhaug Mar 2, 2025
c4f38a8
Refactor Build-PSModuleDocumentation.ps1 to improve output formatting…
MariusStorhaug Mar 2, 2025
5b70ce5
Refactor Build-PSModuleDocumentation.ps1 to improve output formatting…
MariusStorhaug Mar 2, 2025
4ea8c07
Refactor Import-PSModule.ps1 to remove Write-Host for command output;…
MariusStorhaug Mar 2, 2025
26567f0
Add Install-PSModuleHelpers step and remove deprecated helper scripts…
MariusStorhaug Mar 5, 2025
e48d817
Refactor Build-PSModuleDocumentation.ps1 to replace Import-PSModule w…
MariusStorhaug Mar 5, 2025
643013e
Update action.yml to change default WorkingDirectory to '.' for impro…
MariusStorhaug Mar 6, 2025
caad0c6
Remove GITHUB_TOKEN environment variable from Auto-Release workflow f…
MariusStorhaug Mar 8, 2025
25b8d49
Enhance module installation process with retry logic and improved err…
MariusStorhaug Mar 9, 2025
d1f9224
Update README.md and action.yml to enhance documentation and streamli…
MariusStorhaug Apr 17, 2025
ab2e68d
Fix Markdown casing in README.md for consistency
MariusStorhaug Apr 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,16 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4

- name: Initialize environment
uses: PSModule/Initialize-PSModule@main

- name: Upload module artifact
uses: actions/upload-artifact@v4
with:
name: module
path: tests/outputs/modules
path: tests/srcTestRepo/outputs/module
if-no-files-found: error
retention-days: 1

- name: Action-Test
uses: ./
with:
Name: PSModuleTest
Path: tests/src
ModulesOutputPath: tests/outputs/modules
DocsOutputPath: tests/outputs/docs
WorkingDirectory: tests/srcTestRepo
2 changes: 0 additions & 2 deletions .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ jobs:

- name: Auto-Release
uses: PSModule/Auto-Release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
# Template-Action
# Document-PSModule (by PSModule)

A template repository for GitHub Actions
A GitHub Action that automates the generation of documentation for PowerShell modules using Markdown help files.

This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the
[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module.

## Details

This action:
- Installs necessary modules, including `platyPS` for documentation generation.
- Loads helper scripts required by the documentation process.
- Generates Markdown documentation from PowerShell module files.
- Ensures Markdown documentation is properly formatted, with correctly tagged PowerShell code blocks.
- Adjusts Markdown file paths to mirror the structure of the source PowerShell module files.
- Outputs organized Markdown documentation suitable for publishing or distribution.

## Usage

Include this action in your workflow to automatically build and structure documentation for your PowerShell module.

### Inputs

| Input | Description | Required | Default |
|--------------------|-----------------------------------------------|----------|-------------|
| `Name` | Name of the module to document. | No | <Repo name> |
| `WorkingDirectory` | Directory from which the script will execute. | No | `.` |

### Secrets

This action does not require any secrets.

### Outputs

This action does not have defined outputs.

### Example

```yaml
Example here
- name: Document PowerShell Module
uses: PSModule/Document-PSModule@v1
with:
Name: 'MyModule'
WorkingDirectory: './module-directory'
```
73 changes: 12 additions & 61 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-PSModuleDocumentation (by PSModule)
name: Document-PSModule (by PSModule)
description: Build documentation for a PowerShell module.
author: PSModule
branding:
Expand All @@ -9,71 +9,22 @@ inputs:
Name:
description: Name of the module to process.
required: false
Path:
description: Path to the folder where the modules are located.
WorkingDirectory:
description: The working directory where the script will run from.
required: false
default: src
ModulesOutputPath:
description: Path to the folder where the built modules are outputted.
required: false
default: outputs/modules
DocsOutputPath:
description: Path to the folder where the built docs are outputted.
required: false
default: outputs/docs
ModuleArtifactName:
description: Name of the module artifact to upload.
required: false
default: module
DocsArtifactName:
description: Name of the docs artifact to upload.
required: false
default: docs
Debug:
description: Enable debug output.
required: false
default: 'false'
Verbose:
description: Enable verbose output.
required: false
default: 'false'
Version:
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
required: false
Prerelease:
description: Allow prerelease versions if available.
required: false
default: 'false'
default: '.'

runs:
using: composite
steps:
- name: Download module artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.ModuleArtifactName }}
path: ${{ inputs.ModulesOutputPath }}
- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@v1

- name: Run Build-PSModuleDocumentation
uses: PSModule/GitHub-Script@v1
- name: Document-PSModule
shell: pwsh
env:
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
GITHUB_ACTION_INPUT_ModulesOutputPath: ${{ inputs.ModulesOutputPath }}
GITHUB_ACTION_INPUT_DocsOutputPath: ${{ inputs.DocsOutputPath }}
with:
Debug: ${{ inputs.Debug }}
Prerelease: ${{ inputs.Prerelease }}
Verbose: ${{ inputs.Verbose }}
Version: ${{ inputs.Version }}
Script: |
# Build-PSModuleDocumentation
${{ github.action_path }}\scripts\main.ps1

- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.DocsArtifactName }}
path: ${{ inputs.DocsOutputPath }}
if-no-files-found: error
retention-days: 1
working-directory: ${{ inputs.WorkingDirectory }}
run: |
# Build-PSModuleDocumentation
${{ github.action_path }}/scripts/main.ps1
158 changes: 78 additions & 80 deletions scripts/helpers/Build-PSModuleDocumentation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
Builds a module.
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter', '', Scope = 'Function',
Justification = 'LogGroup - Scoping affects the variables line of sight.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '', Scope = 'Function',
Justification = 'Want to just write to the console, not the pipeline.'
)]
#Requires -Modules GitHub
#Requires -Modules Utilities
param(
# Name of the module.
[Parameter(Mandatory)]
Expand All @@ -35,95 +29,99 @@
[string] $DocsOutputFolderPath
)

LogGroup "Documenting module [$ModuleName]" {
Write-Host "Source path: [$ModuleSourceFolderPath]"
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
exit 1
}
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
Write-Host "Module source folder: [$moduleSourceFolder]"

$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
Write-Host "Module output folder: [$moduleOutputFolder]"
Write-Host "::group::Documenting module [$ModuleName]"
[pscustomobject]@{
ModuleName = $ModuleName
ModuleSourceFolderPath = $ModuleSourceFolderPath
ModulesOutputFolderPath = $ModulesOutputFolderPath
DocsOutputFolderPath = $DocsOutputFolderPath
} | Format-List | Out-String

$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force
Write-Host "Docs output folder: [$docsOutputFolder]"
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
exit 1
}
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force

LogGroup 'Build docs - Generate markdown help' {
Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent)
$ModuleName | Remove-Module -Force -ErrorAction SilentlyContinue
Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName
Write-Host ($ModuleName | Get-Module)
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
Write-Host '::group::Build docs - Generate markdown help - Raw'
Install-PSModule -Path $ModuleOutputFolder
Write-Host ($ModuleName | Get-Module)
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$fileName = $_.Name
Write-Host "::group:: - [$fileName]"
Show-FileContent -Path $_
}

LogGroup 'Build docs - Fix markdown code blocks' {
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName
$fixedOpening = $false
$newContent = @()
foreach ($line in $content) {
if ($line -match '^```$' -and -not $fixedOpening) {
$line = $line -replace '^```$', '```powershell'
$fixedOpening = $true
} elseif ($line -match '^```.+$') {
$fixedOpening = $true
} elseif ($line -match '^```$') {
$fixedOpening = $false
}
$newContent += $line
Write-Host '::group::Build docs - Fix markdown code blocks'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName
$fixedOpening = $false
$newContent = @()
foreach ($line in $content) {
if ($line -match '^```$' -and -not $fixedOpening) {
$line = $line -replace '^```$', '```powershell'
$fixedOpening = $true
} elseif ($line -match '^```.+$') {
$fixedOpening = $true
} elseif ($line -match '^```$') {
$fixedOpening = $false
}
$newContent | Set-Content -Path $_.FullName
$newContent += $line
}
$newContent | Set-Content -Path $_.FullName
}

LogGroup 'Build docs - Fix markdown escape characters' {
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName -Raw
$content = $content -replace '\\`', '`'
$content = $content -replace '\\\[', '['
$content = $content -replace '\\\]', ']'
$content = $content -replace '\\\<', '<'
$content = $content -replace '\\\>', '>'
$content = $content -replace '\\\\', '\'
$content | Set-Content -Path $_.FullName
}
Write-Host '::group::Build docs - Fix markdown escape characters'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$content = Get-Content -Path $_.FullName -Raw
$content = $content -replace '\\`', '`'
$content = $content -replace '\\\[', '['
$content = $content -replace '\\\]', ']'
$content = $content -replace '\\\<', '<'
$content = $content -replace '\\\>', '>'
$content = $content -replace '\\\\', '\'
$content | Set-Content -Path $_.FullName
}

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

# find the source code file that matches the markdown file
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
Write-Host "Found script path: $scriptPath"
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
Write-Host "Doc file path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}
# Get the MD files that are in the public functions folder and move them to the same place in the docs folder
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
Write-Host "Processing: $file"
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
Write-Host "Doc file path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}
# find the source code file that matches the markdown file
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
Write-Host " PS1 path: $scriptPath"
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
Write-Host " MD path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}

Write-Host '::group::Build docs - Move markdown files from source files to docs'
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$file = $_
$relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName)
Write-Host " - $relPath"
Write-Host " Path: $file"

$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
Write-Host " MD path: $docsFilePath"
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
$null = New-Item -Path $docsFolderPath -ItemType Directory -Force
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
}

Write-Host '────────────────────────────────────────────────────────────────────────────────'
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$fileName = $_.Name
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
LogGroup " - [$fileName] - [$hash]" {
Show-FileContent -Path $_
}
Write-Host "::group:: - [$fileName]"
Show-FileContent -Path $_
}
}
Loading
Loading