Skip to content

Commit 72f093c

Browse files
Add initial test configurations, modules, and functions
1 parent 21109a3 commit 72f093c

Some content is hidden

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

44 files changed

+1437
-104
lines changed

.github/workflows/Action-Test.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@ on:
88
schedule:
99
- cron: '0 0 * * *'
1010

11+
env:
12+
GH_TOKEN: ${{ github.token }}
13+
1114
concurrency:
1215
group: ${{ github.workflow }}-${{ github.ref }}
1316
cancel-in-progress: true
1417

15-
permissions:
16-
contents: read
17-
pull-requests: read
18+
permissions: {}
1819

1920
jobs:
20-
ActionTestBasic:
21-
name: Action-Test - [Basic]
21+
ActionTestDefault:
22+
name: Action-Test - [Default]
2223
runs-on: ubuntu-latest
2324
steps:
24-
# Need to check out as part of the test, as its a local action
2525
- name: Checkout repo
2626
uses: actions/checkout@v4
2727

28+
- name: Initialize environment
29+
uses: PSModule/Initialize-PSModule@main
30+
2831
- name: Action-Test
2932
uses: ./
3033
with:
31-
working-directory: ./tests
32-
subject: PSModule
34+
Name: PSModuleTest
35+
Path: tests/src
36+
ModulesOutputPath: tests/outputs/modules
37+
DocsOutputPath: tests/outputs/docs

.github/workflows/Auto-Configure.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/Auto-Document.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

action.yml

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,79 @@
1-
name: '{{ NAME }}'
2-
description: '{{ DESCRIPTION }}'
1+
name: Build-PSModuleDocumentation (by PSModule)
2+
description: Build documentation for a PowerShell module.
33
author: PSModule
44
branding:
5-
icon: upload-cloud
6-
color: white
5+
icon: package
6+
color: gray-dark
77

88
inputs:
9-
working-directory:
10-
description: The working directory where Terraform will be executed
9+
Name:
10+
description: Name of the module to process.
1111
required: false
12-
subject:
13-
description: The subject to greet
12+
Path:
13+
description: Path to the folder where the modules are located.
1414
required: false
15-
default: World
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'
1647

1748
runs:
1849
using: composite
1950
steps:
20-
- name: '{{ NAME }}'
51+
- name: Download module artifact
52+
uses: actions/download-artifact@v4
53+
with:
54+
name: ${{ inputs.ModuleArtifactName }}
55+
path: ${{ inputs.ModulesOutputPath }}
56+
57+
- name: Run Build-PSModuleDocumentation
2158
uses: PSModule/GitHub-Script@v1
2259
env:
23-
GITHUB_ACTION_INPUT_subject: ${{ inputs.subject }}
60+
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 }}
2464
with:
65+
Debug: ${{ inputs.Debug }}
66+
Prerelease: ${{ inputs.Prerelease }}
67+
Verbose: ${{ inputs.Verbose }}
68+
Version: ${{ inputs.Version }}
2569
Script: |
26-
# '{{ NAME }}'
70+
# Build-PSModuleDocumentation
2771
${{ 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
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
2+
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
3+
4+
function Build-PSModuleDocumentation {
5+
<#
6+
.SYNOPSIS
7+
Builds a module.
8+
9+
.DESCRIPTION
10+
Builds a module.
11+
#>
12+
[CmdletBinding()]
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
14+
'PSReviewUnusedParameter', '', Scope = 'Function',
15+
Justification = 'LogGroup - Scoping affects the variables line of sight.'
16+
)]
17+
param(
18+
# Name of the module.
19+
[Parameter(Mandatory)]
20+
[string] $ModuleName,
21+
22+
# Path to the folder where the modules are located.
23+
[Parameter(Mandatory)]
24+
[string] $ModuleSourceFolderPath,
25+
26+
# Path to the folder where the built modules are outputted.
27+
[Parameter(Mandatory)]
28+
[string] $ModulesOutputFolderPath,
29+
30+
# Path to the folder where the documentation is outputted.
31+
[Parameter(Mandatory)]
32+
[string] $DocsOutputFolderPath
33+
)
34+
35+
LogGroup "Documenting module [$ModuleName]" {
36+
Write-Host "Source path: [$ModuleSourceFolderPath]"
37+
if (-not (Test-Path -Path $ModuleSourceFolderPath)) {
38+
Write-Error "Source folder not found at [$ModuleSourceFolderPath]"
39+
exit 1
40+
}
41+
$moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath
42+
Write-Host "Module source folder: [$moduleSourceFolder]"
43+
44+
$moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force
45+
Write-Host "Module output folder: [$moduleOutputFolder]"
46+
47+
$docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force
48+
Write-Host "Docs output folder: [$docsOutputFolder]"
49+
}
50+
51+
52+
LogGroup 'Build docs - Generate markdown help' {
53+
$ModuleName | Remove-Module -Force
54+
Import-Module -Name $ModuleName -Force -RequiredVersion '999.0.0'
55+
Write-Host ($ModuleName | Get-Module)
56+
$null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose
57+
}
58+
59+
LogGroup 'Build docs - Fix markdown code blocks' {
60+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
61+
$content = Get-Content -Path $_.FullName
62+
$fixedOpening = $false
63+
$newContent = @()
64+
foreach ($line in $content) {
65+
if ($line -match '^```$' -and -not $fixedOpening) {
66+
$line = $line -replace '^```$', '```powershell'
67+
$fixedOpening = $true
68+
} elseif ($line -match '^```.+$') {
69+
$fixedOpening = $true
70+
} elseif ($line -match '^```$') {
71+
$fixedOpening = $false
72+
}
73+
$newContent += $line
74+
}
75+
$newContent | Set-Content -Path $_.FullName
76+
}
77+
}
78+
79+
LogGroup 'Build docs - Fix markdown escape characters' {
80+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
81+
$content = Get-Content -Path $_.FullName -Raw
82+
$content = $content -replace '\\`', '`'
83+
$content = $content -replace '\\\[', '['
84+
$content = $content -replace '\\\]', ']'
85+
$content = $content -replace '\\\<', '<'
86+
$content = $content -replace '\\\>', '>'
87+
$content = $content -replace '\\\\', '\'
88+
$content | Set-Content -Path $_.FullName
89+
}
90+
}
91+
92+
LogGroup 'Build docs - Structure markdown files to match source files' {
93+
$PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item
94+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
95+
$file = $_
96+
Write-Host "Processing: $file"
97+
98+
# find the source code file that matches the markdown file
99+
$scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') }
100+
Write-Host "Found script path: $scriptPath"
101+
$docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md')
102+
Write-Host "Doc file path: $docsFilePath"
103+
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
104+
New-Item -Path $docsFolderPath -ItemType Directory -Force
105+
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
106+
}
107+
# Get the MD files that are in the public functions folder and move them to the same place in the docs folder
108+
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
109+
$file = $_
110+
Write-Host "Processing: $file"
111+
$docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName)
112+
Write-Host "Doc file path: $docsFilePath"
113+
$docsFolderPath = Split-Path -Path $docsFilePath -Parent
114+
New-Item -Path $docsFolderPath -ItemType Directory -Force
115+
Move-Item -Path $file.FullName -Destination $docsFilePath -Force
116+
}
117+
}
118+
119+
Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object {
120+
$fileName = $_.Name
121+
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
122+
LogGroup " - [$fileName] - [$hash]" {
123+
Show-FileContent -Path $_
124+
}
125+
}
126+
}

scripts/main.ps1

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
1-
#Requires -Modules GitHub
1+
#Requires -Modules Utilities
22

33
[CmdletBinding()]
4-
param(
5-
[Parameter()]
6-
[string] $Subject = $env:GITHUB_ACTION_INPUT_subject
7-
)
8-
9-
begin {
10-
$scriptName = $MyInvocation.MyCommand.Name
11-
Write-Debug "[$scriptName] - Start"
4+
param()
5+
6+
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative
7+
LogGroup "Loading helper scripts from [$path]" {
8+
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object {
9+
Write-Host "$_"
10+
. $_
11+
}
12+
}
13+
14+
LogGroup 'Loading inputs' {
15+
$moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
16+
Write-Host "Module name: [$moduleName]"
17+
18+
$moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/$moduleName
19+
if (-not (Test-Path -Path $moduleSourceFolderPath)) {
20+
$moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path
21+
}
22+
Write-Host "Source module path: [$moduleSourceFolderPath]"
23+
if (-not (Test-Path -Path $moduleSourceFolderPath)) {
24+
throw "Module path [$moduleSourceFolderPath] does not exist."
25+
}
26+
27+
$modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath
28+
Write-Host "Modules output path: [$modulesOutputFolderPath]"
29+
$docsOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_DocsOutputPath
30+
Write-Host "Docs output path: [$docsOutputFolderPath]"
1231
}
1332

14-
process {
15-
try {
16-
Write-Output "Hello, $Subject!"
17-
} catch {
18-
throw $_
33+
LogGroup 'Build local scripts' {
34+
Write-Host 'Execution order:'
35+
$scripts = Get-ChildItem -Filter '*build.ps1' -Recurse | Sort-Object -Property Name | Resolve-Path -Relative
36+
$scripts | ForEach-Object {
37+
Write-Host " - $_"
38+
}
39+
$scripts | ForEach-Object {
40+
LogGroup "Build local scripts - [$_]" {
41+
. $_
42+
}
1943
}
2044
}
2145

22-
end {
23-
Write-Debug "[$scriptName] - End"
46+
$params = @{
47+
ModuleName = $moduleName
48+
ModuleSourceFolderPath = $moduleSourceFolderPath
49+
ModulesOutputFolderPath = $modulesOutputFolderPath
50+
DocsOutputFolderPath = $docsOutputFolderPath
2451
}
52+
53+
Build-PSModuleDocumentation @params

tests/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)