Skip to content

Commit 2431ed2

Browse files
🔧 [CI]: Add Build-Site workflow and integrate it into the main workflow
1 parent ab5fa6b commit 2431ed2

File tree

5 files changed

+213
-146
lines changed

5 files changed

+213
-146
lines changed

.github/workflows/Build-Docs.yml

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -108,136 +108,3 @@ jobs:
108108
VALIDATE_YAML_PRETTIER: false
109109
VALIDATE_JSCPD: false
110110
VALIDATE_GITLEAKS: false
111-
112-
- uses: actions/configure-pages@v5
113-
114-
- name: Install mkdoks-material
115-
shell: pwsh
116-
run: |
117-
pip install mkdocs-material
118-
pip install mkdocs-git-authors-plugin
119-
pip install mkdocs-git-revision-date-localized-plugin
120-
pip install mkdocs-git-committers-plugin-2
121-
122-
- name: Structure site
123-
uses: PSModule/GitHub-Script@v1
124-
with:
125-
Debug: ${{ inputs.Debug }}
126-
Prerelease: ${{ inputs.Prerelease }}
127-
Verbose: ${{ inputs.Verbose }}
128-
Version: ${{ inputs.Version }}
129-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
130-
Script: |
131-
LogGroup "Get folder structure" {
132-
$functionDocsFolder = New-Item -Path "outputs/site/docs/Functions" -ItemType Directory -Force
133-
Copy-Item -Path "outputs/docs/*" -Destination "outputs/site/docs/Functions" -Recurse -Force
134-
$moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}'
135-
$ModuleSourcePath = Resolve-Path 'src' | Select-Object -ExpandProperty Path
136-
$SiteOutputPath = Resolve-Path 'outputs/site' | Select-Object -ExpandProperty Path
137-
138-
Write-Host "Function Docs Folder: $functionDocsFolder"
139-
Write-Host "Module Name: $moduleName"
140-
Write-Host "Module Source Path: $ModuleSourcePath"
141-
Write-Host "Site Output Path: $SiteOutputPath"
142-
}
143-
144-
LogGroup "Get folder structure" {
145-
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object | Format-List
146-
}
147-
148-
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
149-
$fileName = $_.Name
150-
LogGroup " - $fileName" {
151-
Show-FileContent -Path $_
152-
}
153-
}
154-
155-
LogGroup 'Build docs - Process about topics' {
156-
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
157-
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
158-
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
159-
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
160-
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
161-
162-
Write-Host "About Docs Folder: $aboutDocsFolder"
163-
Write-Host "About Source Folder: $aboutSourceFolder"
164-
}
165-
166-
LogGroup 'Build docs - Copy icon to assets' {
167-
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
168-
$assetsFolder = New-Item -Path $assetsFolderPath -ItemType Directory -Force
169-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
170-
$iconPath = Resolve-Path 'icon\icon.png' | Select-Object -ExpandProperty Path
171-
Copy-Item -Path $iconPath -Destination $assetsFolder -Force -Verbose
172-
173-
Write-Host "Assets Folder: $assetsFolder"
174-
Write-Host "Icon Path: $iconPath"
175-
}
176-
177-
LogGroup 'Build docs - Copy readme.md' {
178-
$readmePath = Resolve-Path 'README.md' | Select-Object -ExpandProperty Path
179-
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
180-
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
181-
182-
Write-Host "Readme Path: $readmePath"
183-
Write-Host "Readme Target Path: $readmeTargetPath"
184-
}
185-
186-
LogGroup 'Build docs - Create mkdocs.yml' {
187-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
188-
$possiblePaths = @(
189-
'.github/mkdocs.yml',
190-
'docs/mkdocs.yml',
191-
'mkdocs.yml'
192-
)
193-
194-
$mkdocsSourcePath = $null
195-
foreach ($path in $possiblePaths) {
196-
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
197-
if (Test-Path -Path $candidatePath) {
198-
$mkdocsSourcePath = $candidatePath
199-
break
200-
}
201-
}
202-
203-
if (-not $mkdocsSourcePath) {
204-
throw "Mkdocs source file not found in any of the expected locations: $($possiblePaths -join ', ')"
205-
}
206-
207-
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
208-
209-
Write-Host "Mkdocs Source Path: $mkdocsSourcePath"
210-
Write-Host "Mkdocs Target Path: $mkdocsTargetPath"
211-
212-
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
213-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
214-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
215-
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
216-
Show-FileContent -Path $mkdocsTargetPath
217-
}
218-
219-
- name: Debug File system
220-
shell: pwsh
221-
working-directory: ${{ inputs.WorkingDirectory }}
222-
run: |
223-
Get-ChildItem -Path . -Recurse | ForEach-Object {
224-
[System.IO.Path]::GetRelativePath($PSScriptRoot, $_.FullName)
225-
} | Sort-Object
226-
227-
- name: Build mkdocs-material project
228-
working-directory: ${{ inputs.WorkingDirectory }}/outputs/site
229-
shell: pwsh
230-
run: |
231-
LogGroup 'Build docs - mkdocs build - content' {
232-
Show-FileContent -Path mkdocs.yml
233-
}
234-
235-
LogGroup 'Build docs - mkdocs build' {
236-
mkdocs build --config-file mkdocs.yml --site-dir ../../_site
237-
}
238-
239-
- uses: actions/upload-pages-artifact@v3
240-
with:
241-
name: github-pages
242-
path: ${{ inputs.WorkingDirectory }}/_site
243-
retention-days: 1

.github/workflows/Build-Site.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Build-Site
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
Name:
7+
type: string
8+
description: The name of the module to process. Scripts default to the repository name if nothing is specified.
9+
required: false
10+
Debug:
11+
type: boolean
12+
description: Enable debug output.
13+
required: false
14+
default: false
15+
Verbose:
16+
type: boolean
17+
description: Enable verbose output.
18+
required: false
19+
default: false
20+
Version:
21+
type: string
22+
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
23+
required: false
24+
default: ''
25+
Prerelease:
26+
type: boolean
27+
description: Whether to use a prerelease version of the 'GitHub' module.
28+
required: false
29+
default: false
30+
WorkingDirectory:
31+
type: string
32+
description: The working directory where the script will run from.
33+
required: false
34+
default: '.'
35+
36+
permissions:
37+
contents: read # to checkout the repo
38+
39+
jobs:
40+
Build-Site:
41+
name: Build-Site
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout Code
45+
uses: actions/checkout@v4
46+
with:
47+
fetch-depth: 0
48+
49+
- name: Download docs artifact
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: docs
53+
path: ${{ inputs.WorkingDirectory }}/outputs/docs
54+
55+
- name: Install mkdocs-material
56+
shell: pwsh
57+
run: |
58+
pip install mkdocs-material
59+
pip install mkdocs-git-authors-plugin
60+
pip install mkdocs-git-revision-date-localized-plugin
61+
pip install mkdocs-git-committers-plugin-2
62+
63+
- name: Structure site
64+
uses: PSModule/GitHub-Script@v1
65+
with:
66+
Debug: ${{ inputs.Debug }}
67+
Prerelease: ${{ inputs.Prerelease }}
68+
Verbose: ${{ inputs.Verbose }}
69+
Version: ${{ inputs.Version }}
70+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
71+
Script: |
72+
LogGroup "Get folder structure" {
73+
$functionDocsFolder = New-Item -Path "outputs/site/docs/Functions" -ItemType Directory -Force
74+
Copy-Item -Path "outputs/docs/*" -Destination "outputs/site/docs/Functions" -Recurse -Force
75+
$moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}'
76+
$ModuleSourcePath = Resolve-Path 'src' | Select-Object -ExpandProperty Path
77+
$SiteOutputPath = Resolve-Path 'outputs/site' | Select-Object -ExpandProperty Path
78+
79+
Write-Host "Function Docs Folder: $functionDocsFolder"
80+
Write-Host "Module Name: $moduleName"
81+
Write-Host "Module Source Path: $ModuleSourcePath"
82+
Write-Host "Site Output Path: $SiteOutputPath"
83+
}
84+
85+
LogGroup "Get folder structure" {
86+
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object | Format-List
87+
}
88+
89+
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
90+
$fileName = $_.Name
91+
LogGroup " - $fileName" {
92+
Show-FileContent -Path $_
93+
}
94+
}
95+
96+
LogGroup 'Build docs - Process about topics' {
97+
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
98+
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
99+
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
100+
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
101+
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
102+
103+
Write-Host "About Docs Folder: $aboutDocsFolder"
104+
Write-Host "About Source Folder: $aboutSourceFolder"
105+
}
106+
107+
LogGroup 'Build docs - Copy icon to assets' {
108+
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
109+
$assetsFolder = New-Item -Path $assetsFolderPath -ItemType Directory -Force
110+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
111+
$iconPath = Resolve-Path 'icon\icon.png' | Select-Object -ExpandProperty Path
112+
Copy-Item -Path $iconPath -Destination $assetsFolder -Force -Verbose
113+
114+
Write-Host "Assets Folder: $assetsFolder"
115+
Write-Host "Icon Path: $iconPath"
116+
}
117+
118+
LogGroup 'Build docs - Copy readme.md' {
119+
$readmePath = Resolve-Path 'README.md' | Select-Object -ExpandProperty Path
120+
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
121+
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
122+
123+
Write-Host "Readme Path: $readmePath"
124+
Write-Host "Readme Target Path: $readmeTargetPath"
125+
}
126+
127+
LogGroup 'Build docs - Create mkdocs.yml' {
128+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
129+
$possiblePaths = @(
130+
'.github/mkdocs.yml',
131+
'docs/mkdocs.yml',
132+
'mkdocs.yml'
133+
)
134+
135+
$mkdocsSourcePath = $null
136+
foreach ($path in $possiblePaths) {
137+
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
138+
if (Test-Path -Path $candidatePath) {
139+
$mkdocsSourcePath = $candidatePath
140+
break
141+
}
142+
}
143+
144+
if (-not $mkdocsSourcePath) {
145+
throw "Mkdocs source file not found in any of the expected locations: $($possiblePaths -join ', ')"
146+
}
147+
148+
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
149+
150+
Write-Host "Mkdocs Source Path: $mkdocsSourcePath"
151+
Write-Host "Mkdocs Target Path: $mkdocsTargetPath"
152+
153+
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
154+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
155+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
156+
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
157+
Show-FileContent -Path $mkdocsTargetPath
158+
}
159+
160+
- name: Build mkdocs-material project
161+
working-directory: ${{ inputs.WorkingDirectory }}/outputs/site
162+
shell: pwsh
163+
run: |
164+
LogGroup 'Build docs - mkdocs build - content' {
165+
Show-FileContent -Path mkdocs.yml
166+
}
167+
168+
LogGroup 'Build docs - mkdocs build' {
169+
mkdocs build --config-file mkdocs.yml --site-dir ../../_site
170+
}
171+
172+
- uses: actions/upload-pages-artifact@v3
173+
with:
174+
name: github-pages
175+
path: ${{ inputs.WorkingDirectory }}/_site
176+
retention-days: 1

.github/workflows/Get-Settings.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ jobs:
137137
}
138138
139139
$settings = [pscustomobject]@{
140-
Name = $name
141-
Test = [pscustomobject]@{
140+
Name = $name
141+
Test = [pscustomobject]@{
142142
Skip = $settings.Test.Skip ?? $false
143143
Linux = [pscustomobject]@{
144144
Skip = $settings.Test.Linux.Skip ?? $false
@@ -194,25 +194,32 @@ jobs:
194194
StepSummaryMode = $settings.Test.CodeCoverage.StepSummary_Mode ?? 'Missed, Files'
195195
}
196196
}
197-
Build = [pscustomobject]@{
197+
Build = [pscustomobject]@{
198198
Skip = $settings.Build.Skip ?? $false
199199
Module = [pscustomobject]@{
200200
Skip = $settings.Build.Module.Skip ?? $false
201201
}
202202
Docs = [pscustomobject]@{
203203
Skip = $settings.Build.Docs.Skip ?? $false
204204
}
205+
Site = [pscustomobject]@{
206+
Skip = $settings.Build.Site.Skip ?? $false
207+
}
205208
}
206209
Publish = [pscustomobject]@{
207-
AutoCleanup = $settings.Publish.AutoCleanup ?? $true
208-
AutoPatching = $settings.Publish.AutoPatching ?? $true
209-
IncrementalPrerelease = $settings.Publish.IncrementalPrerelease ?? $true
210-
DatePrereleaseFormat = $settings.Publish.DatePrereleaseFormat ?? ''
211-
VersionPrefix = $settings.Publish.VersionPrefix ?? 'v'
212-
MajorLabels = $settings.Publish.MajorLabels ?? 'major, breaking'
213-
MinorLabels = $settings.Publish.MinorLabels ?? 'minor, feature'
214-
PatchLabels = $settings.Publish.PatchLabels ?? 'patch, fix'
215-
IgnoreLabels = $settings.Publish.IgnoreLabels ?? 'NoRelease'
210+
Module = [pscustomobject]@{
211+
Skip = $settings.Publish.Module.Skip ?? $false
212+
AutoCleanup = $settings.Publish.Module.AutoCleanup ?? $true
213+
AutoPatching = $settings.Publish.Module.AutoPatching ?? $true
214+
IncrementalPrerelease = $settings.Publish.Module.IncrementalPrerelease ?? $true
215+
DatePrereleaseFormat = $settings.Publish.Module.DatePrereleaseFormat ?? ''
216+
VersionPrefix = $settings.Publish.Module.VersionPrefix ?? 'v'
217+
MajorLabels = $settings.Publish.Module.MajorLabels ?? 'major, breaking'
218+
MinorLabels = $settings.Publish.Module.MinorLabels ?? 'minor, feature'
219+
PatchLabels = $settings.Publish.Module.PatchLabels ?? 'patch, fix'
220+
IgnoreLabels = $settings.Publish.Module.IgnoreLabels ?? 'NoRelease'
221+
}
222+
216223
}
217224
}
218225
LogGroup "Final settings" {

.github/workflows/workflow.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ jobs:
145145
Version: ${{ inputs.Version }}
146146
WorkingDirectory: ${{ inputs.WorkingDirectory }}
147147

148+
Build-Site:
149+
if: ${{ fromJson(needs.Get-Settings.outputs.Settings).Build.Site.Skip != true }}
150+
needs:
151+
- Get-Settings
152+
- Build-Docs
153+
uses: ./.github/workflows/Build-Site.yml
154+
with:
155+
Name: ${{ fromJson(needs.Get-Settings.outputs.Settings).Name }}
156+
Debug: ${{ inputs.Debug }}
157+
Prerelease: ${{ inputs.Prerelease }}
158+
Verbose: ${{ inputs.Verbose }}
159+
Version: ${{ inputs.Version }}
160+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
161+
148162
Test-Module:
149163
if: ${{ needs.Build-Module.result == 'success' && !cancelled() && needs.Get-Settings.outputs.PSModuleTestSuites != '[]' }}
150164
needs:
@@ -286,6 +300,8 @@ jobs:
286300
url: ${{ steps.deployment.outputs.page_url }}
287301
runs-on: ubuntu-latest
288302
steps:
303+
- uses: actions/configure-pages@v5
304+
289305
- name: Deploy to GitHub Pages
290306
id: deployment
291307
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)