Skip to content

Commit 214dfb3

Browse files
Extract all multiline Build-Site steps
Move every multiline run/Script step in Build-Site into internal composite actions with src scripts: Install-Zensical, Structure-Site, Build-ZensicalSite, and keep Inject-SiteScripts as action-backed invocation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent d5deb4d commit 214dfb3

8 files changed

Lines changed: 157 additions & 138 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Build-ZensicalSite
2+
description: Build Zensical site output and normalize output folder.
3+
4+
inputs:
5+
WorkingDirectory:
6+
description: Working directory for the repository build.
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Build documentation site
13+
shell: pwsh
14+
run: '& "${{ github.action_path }}/src/build-zensical-site.ps1" -WorkingDirectory "${{ inputs.WorkingDirectory }}"'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
param(
2+
[Parameter(Mandatory)]
3+
[string]$WorkingDirectory
4+
)
5+
6+
$ErrorActionPreference = 'Stop'
7+
8+
$resolvedWorkingDirectory = Resolve-Path -Path $WorkingDirectory | Select-Object -ExpandProperty Path
9+
$siteWorkingDirectory = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'outputs/site'
10+
$outputSitePath = Join-Path -Path $resolvedWorkingDirectory -ChildPath '_site'
11+
12+
Set-Location -Path $siteWorkingDirectory
13+
14+
if (-not (Test-Path -Path 'zensical.toml')) {
15+
throw "No documentation config file found in outputs/site. Expected zensical.toml."
16+
}
17+
18+
zensical build --config-file 'zensical.toml'
19+
20+
if (Test-Path -Path '_site') {
21+
if (Test-Path -Path $outputSitePath) {
22+
Remove-Item -Path $outputSitePath -Recurse -Force
23+
}
24+
Move-Item -Path '_site' -Destination $outputSitePath -Force
25+
}
26+
27+
if (-not (Test-Path -Path $outputSitePath)) {
28+
throw "Expected Zensical output at $outputSitePath but it was not created."
29+
}

.github/actions/Inject-SiteScripts/action.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@ runs:
1515
steps:
1616
- name: Inject site scripts
1717
shell: pwsh
18-
run: |
19-
& "${{ github.action_path }}/src/inject-site-scripts.ps1" `
20-
-SitePath "${{ inputs.SitePath }}" `
21-
-WorkflowPath "${{ inputs.WorkflowPath }}"
18+
run: '& "${{ github.action_path }}/src/inject-site-scripts.ps1" -SitePath "${{ inputs.SitePath }}" -WorkflowPath "${{ inputs.WorkflowPath }}"'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Install-Zensical
2+
description: Install Zensical CLI used for documentation site generation.
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install Zensical CLI
8+
shell: pwsh
9+
run: '& "${{ github.action_path }}/src/install-zensical.ps1"'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
pip install zensical
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Structure-Site
2+
description: Structure generated docs and create site config for Zensical.
3+
4+
inputs:
5+
WorkingDirectory:
6+
description: Working directory for the repository build.
7+
required: true
8+
Name:
9+
description: Optional module name override.
10+
required: false
11+
default: ''
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Structure site content and config
17+
shell: pwsh
18+
run: '& "${{ github.action_path }}/src/structure-site.ps1" -WorkingDirectory "${{ inputs.WorkingDirectory }}" -Name "${{ inputs.Name }}"'
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
param(
2+
[Parameter(Mandatory)]
3+
[string]$WorkingDirectory,
4+
5+
[Parameter()]
6+
[string]$Name
7+
)
8+
9+
$ErrorActionPreference = 'Stop'
10+
11+
$resolvedWorkingDirectory = Resolve-Path -Path $WorkingDirectory | Select-Object -ExpandProperty Path
12+
$siteOutputPath = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'outputs/site'
13+
$docsOutputPath = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'outputs/docs'
14+
$moduleSourcePath = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'src'
15+
$moduleName = if ([string]::IsNullOrEmpty($Name)) { $env:GITHUB_REPOSITORY_NAME } else { $Name }
16+
17+
$functionDocsFolder = New-Item -Path (Join-Path -Path $siteOutputPath -ChildPath 'docs/Functions') -ItemType Directory -Force
18+
Copy-Item -Path (Join-Path -Path $docsOutputPath -ChildPath '*') -Destination $functionDocsFolder.FullName -Recurse -Force
19+
20+
Write-Host "Function Docs Folder: $($functionDocsFolder.FullName)"
21+
Write-Host "Module Name: $moduleName"
22+
Write-Host "Module Source Path: $moduleSourcePath"
23+
Write-Host "Site Output Path: $siteOutputPath"
24+
25+
$aboutDocsFolder = New-Item -Path (Join-Path -Path $siteOutputPath -ChildPath 'docs/About') -ItemType Directory -Force
26+
$aboutSourceFolder = Join-Path -Path $moduleSourcePath -ChildPath 'en-US'
27+
if (Test-Path -Path $aboutSourceFolder) {
28+
Get-ChildItem -Path $aboutSourceFolder -Filter '*.txt' | Copy-Item -Destination $aboutDocsFolder.FullName -Force -PassThru |
29+
Rename-Item -NewName { $_.Name -replace '\.txt$', '.md' }
30+
}
31+
32+
$assetsFolder = New-Item -Path (Join-Path -Path $siteOutputPath -ChildPath 'docs/Assets') -ItemType Directory -Force
33+
$iconPath = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'icon/icon.png'
34+
if (Test-Path -Path $iconPath) {
35+
Copy-Item -Path $iconPath -Destination $assetsFolder.FullName -Force
36+
}
37+
38+
$readmePath = Join-Path -Path $resolvedWorkingDirectory -ChildPath 'README.md'
39+
$readmeTargetPath = Join-Path -Path $siteOutputPath -ChildPath 'docs/README.md'
40+
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force
41+
42+
$possiblePaths = @(
43+
'.github/zensical.toml',
44+
'docs/zensical.toml',
45+
'zensical.toml'
46+
)
47+
48+
$docsConfigSourcePath = $null
49+
foreach ($relativePath in $possiblePaths) {
50+
$candidatePath = Join-Path -Path $resolvedWorkingDirectory -ChildPath $relativePath
51+
if (Test-Path -Path $candidatePath) {
52+
$docsConfigSourcePath = $candidatePath
53+
break
54+
}
55+
}
56+
57+
if (-not $docsConfigSourcePath) {
58+
throw "Documentation config file not found. Expected one of: $($possiblePaths -join ', ')"
59+
}
60+
61+
$docsConfigFileName = [System.IO.Path]::GetFileName($docsConfigSourcePath)
62+
$docsConfigTargetPath = Join-Path -Path $siteOutputPath -ChildPath $docsConfigFileName
63+
64+
$docsConfigContent = Get-Content -Path $docsConfigSourcePath -Raw
65+
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_NAME }}-', $moduleName)
66+
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
67+
68+
if ($docsConfigFileName -eq 'zensical.toml') {
69+
if ($docsConfigContent -match '(?m)^\s*site_dir\s*=') {
70+
$docsConfigContent = $docsConfigContent -replace '(?m)^\s*site_dir\s*=.*$', 'site_dir = "_site"'
71+
} else {
72+
$docsConfigContent = $docsConfigContent -replace '(?m)^\[project\]\s*$', "[project]`nsite_dir = ""_site"""
73+
}
74+
}
75+
76+
Set-Content -Path $docsConfigTargetPath -Value $docsConfigContent -Force
77+
Write-Host "Build Config Type: $docsConfigFileName"

.github/workflows/Build-Site.yml

Lines changed: 6 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -40,146 +40,18 @@ jobs:
4040
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
4141

4242
- name: Install Zensical
43-
shell: pwsh
44-
run: |
45-
pip install zensical
43+
uses: ./_wf/.github/actions/Install-Zensical
4644

4745
- name: Structure site
48-
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
46+
uses: ./_wf/.github/actions/Structure-Site
4947
with:
50-
Debug: ${{ fromJson(inputs.Settings).Debug }}
51-
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
52-
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
53-
Version: ${{ fromJson(inputs.Settings).Version }}
5448
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
55-
Script: |
56-
LogGroup "Get folder structure" {
57-
$functionDocsFolder = New-Item -Path "outputs/site/docs/Functions" -ItemType Directory -Force
58-
Copy-Item -Path "outputs/docs/*" -Destination "outputs/site/docs/Functions" -Recurse -Force
59-
$moduleName = [string]::IsNullOrEmpty('${{ fromJson(inputs.Settings).Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ fromJson(inputs.Settings).Name }}'
60-
$ModuleSourcePath = Resolve-Path 'src' | Select-Object -ExpandProperty Path
61-
$SiteOutputPath = Resolve-Path 'outputs/site' | Select-Object -ExpandProperty Path
62-
63-
Write-Host "Function Docs Folder: $functionDocsFolder"
64-
Write-Host "Module Name: $moduleName"
65-
Write-Host "Module Source Path: $ModuleSourcePath"
66-
Write-Host "Site Output Path: $SiteOutputPath"
67-
}
68-
69-
LogGroup "Get folder structure" {
70-
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object | Format-List
71-
}
72-
73-
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
74-
$fileName = $_.Name
75-
LogGroup " - $fileName" {
76-
Show-FileContent -Path $_
77-
}
78-
}
79-
80-
LogGroup 'Build docs - Process about topics' {
81-
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
82-
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
83-
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
84-
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
85-
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
86-
87-
Write-Host "About Docs Folder: $aboutDocsFolder"
88-
Write-Host "About Source Folder: $aboutSourceFolder"
89-
}
90-
91-
LogGroup 'Build docs - Copy icon to assets' {
92-
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
93-
$assetsFolder = New-Item -Path $assetsFolderPath -ItemType Directory -Force
94-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
95-
$iconPath = Resolve-Path 'icon\icon.png' | Select-Object -ExpandProperty Path
96-
Copy-Item -Path $iconPath -Destination $assetsFolder -Force -Verbose
97-
98-
Write-Host "Assets Folder: $assetsFolder"
99-
Write-Host "Icon Path: $iconPath"
100-
}
101-
102-
LogGroup 'Build docs - Copy readme.md' {
103-
$readmePath = Resolve-Path 'README.md' | Select-Object -ExpandProperty Path
104-
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
105-
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
106-
107-
Write-Host "Readme Path: $readmePath"
108-
Write-Host "Readme Target Path: $readmeTargetPath"
109-
}
110-
111-
LogGroup 'Build docs - Create docs config' {
112-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
113-
$possiblePaths = @(
114-
'.github/zensical.toml',
115-
'docs/zensical.toml',
116-
'zensical.toml'
117-
)
118-
119-
$docsConfigSourcePath = $null
120-
foreach ($path in $possiblePaths) {
121-
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
122-
if (Test-Path -Path $candidatePath) {
123-
$docsConfigSourcePath = $candidatePath
124-
break
125-
}
126-
}
127-
128-
if (-not $docsConfigSourcePath) {
129-
throw "Documentation config file not found. Expected one of: $($possiblePaths -join ', ')"
130-
}
131-
132-
$docsConfigFileName = [System.IO.Path]::GetFileName($docsConfigSourcePath)
133-
$docsConfigTargetPath = Join-Path -Path $SiteOutputPath -ChildPath $docsConfigFileName
134-
135-
Write-Host "Docs Config Source: $docsConfigSourcePath"
136-
Write-Host "Docs Config Target: $docsConfigTargetPath"
137-
138-
$docsConfigContent = Get-Content -Path $docsConfigSourcePath -Raw
139-
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
140-
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
141-
if ($docsConfigFileName -eq 'zensical.toml') {
142-
if ($docsConfigContent -match '(?m)^\s*site_dir\s*=') {
143-
$docsConfigContent = $docsConfigContent -replace '(?m)^\s*site_dir\s*=.*$', 'site_dir = "_site"'
144-
} else {
145-
$docsConfigContent = $docsConfigContent -replace '(?m)^\[project\]\s*$', "[project]`nsite_dir = ""_site"""
146-
}
147-
}
148-
$docsConfigContent | Set-Content -Path $docsConfigTargetPath -Force
149-
150-
Write-Host "Build Config Type: $docsConfigFileName"
151-
Show-FileContent -Path $docsConfigTargetPath
152-
}
49+
Name: ${{ fromJson(inputs.Settings).Name }}
15350

15451
- name: Build documentation site with Zensical
155-
working-directory: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/site
156-
shell: pwsh
157-
run: |
158-
if (-not (Test-Path -Path 'zensical.toml')) {
159-
throw "No documentation config file found in outputs/site. Expected zensical.toml."
160-
}
161-
$configFile = 'zensical.toml'
162-
163-
LogGroup 'Build docs - Zensical config content' {
164-
Write-Host "Using config: $configFile"
165-
Show-FileContent -Path $configFile
166-
}
167-
168-
LogGroup 'Build docs - Zensical build' {
169-
zensical build --config-file $configFile
170-
}
171-
172-
LogGroup 'Build docs - verify output' {
173-
if (Test-Path -Path '_site') {
174-
if (Test-Path -Path '../../_site') {
175-
Remove-Item -Path '../../_site' -Recurse -Force
176-
}
177-
Move-Item -Path '_site' -Destination '../../_site' -Force
178-
}
179-
if (-not (Test-Path -Path '../../_site')) {
180-
throw "Expected Zensical output at ../../_site but it was not created."
181-
}
182-
}
52+
uses: ./_wf/.github/actions/Build-ZensicalSite
53+
with:
54+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
18355

18456
- name: Inject shared site scripts
18557
uses: ./_wf/.github/actions/Inject-SiteScripts

0 commit comments

Comments
 (0)