-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (164 loc) · 8.45 KB
/
Copy pathBuild-Site.yml
File metadata and controls
194 lines (164 loc) · 8.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Build-Site
on:
workflow_call:
inputs:
Settings:
type: string
description: The complete settings object.
required: true
permissions:
contents: read # to checkout the repo
jobs:
Build-Site:
name: Build-Site
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
fetch-depth: 0
- name: Checkout Process-PSModule
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: _wf
persist-credentials: false
- name: Install-PSModule
uses: ./_wf/.github/actions/Install-PSModule
- name: Download docs artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: docs
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
- name: Install Zensical
shell: pwsh
run: |
pip install zensical
- name: Structure site
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
with:
Debug: ${{ fromJson(inputs.Settings).Debug }}
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
Verbose: ${{ fromJson(inputs.Settings).Verbose }}
Version: ${{ fromJson(inputs.Settings).Version }}
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
Script: |
LogGroup "Get folder structure" {
$functionDocsFolder = New-Item -Path "outputs/site/docs/Functions" -ItemType Directory -Force
Copy-Item -Path "outputs/docs/*" -Destination "outputs/site/docs/Functions" -Recurse -Force
$moduleName = [string]::IsNullOrEmpty('${{ fromJson(inputs.Settings).Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ fromJson(inputs.Settings).Name }}'
$ModuleSourcePath = Resolve-Path 'src' | Select-Object -ExpandProperty Path
$SiteOutputPath = Resolve-Path 'outputs/site' | Select-Object -ExpandProperty Path
Write-Host "Function Docs Folder: $functionDocsFolder"
Write-Host "Module Name: $moduleName"
Write-Host "Module Source Path: $ModuleSourcePath"
Write-Host "Site Output Path: $SiteOutputPath"
}
LogGroup "Get folder structure" {
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object | Format-List
}
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
$fileName = $_.Name
LogGroup " - $fileName" {
Show-FileContent -Path $_
}
}
LogGroup 'Build docs - Process about topics' {
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
Write-Host "About Docs Folder: $aboutDocsFolder"
Write-Host "About Source Folder: $aboutSourceFolder"
}
LogGroup 'Build docs - Copy icon to assets' {
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
$assetsFolder = New-Item -Path $assetsFolderPath -ItemType Directory -Force
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
$iconPath = Resolve-Path 'icon\icon.png' | Select-Object -ExpandProperty Path
Copy-Item -Path $iconPath -Destination $assetsFolder -Force -Verbose
Write-Host "Assets Folder: $assetsFolder"
Write-Host "Icon Path: $iconPath"
}
LogGroup 'Build docs - Copy readme.md' {
$readmePath = Resolve-Path 'README.md' | Select-Object -ExpandProperty Path
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
Write-Host "Readme Path: $readmePath"
Write-Host "Readme Target Path: $readmeTargetPath"
}
LogGroup 'Build docs - Create docs config' {
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
$possiblePaths = @(
'.github/zensical.toml',
'docs/zensical.toml',
'zensical.toml'
)
$docsConfigSourcePath = $null
foreach ($path in $possiblePaths) {
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
if (Test-Path -Path $candidatePath) {
$docsConfigSourcePath = $candidatePath
break
}
}
if (-not $docsConfigSourcePath) {
throw "Documentation config file not found. Expected one of: $($possiblePaths -join ', ')"
}
$docsConfigFileName = [System.IO.Path]::GetFileName($docsConfigSourcePath)
$docsConfigTargetPath = Join-Path -Path $SiteOutputPath -ChildPath $docsConfigFileName
Write-Host "Docs Config Source: $docsConfigSourcePath"
Write-Host "Docs Config Target: $docsConfigTargetPath"
$docsConfigContent = Get-Content -Path $docsConfigSourcePath -Raw
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
$docsConfigContent = $docsConfigContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
if ($docsConfigFileName -eq 'zensical.toml') {
if ($docsConfigContent -match '(?m)^\s*site_dir\s*=') {
$docsConfigContent = $docsConfigContent -replace '(?m)^\s*site_dir\s*=.*$', 'site_dir = "_site"'
} else {
$docsConfigContent = $docsConfigContent -replace '(?m)^\[project\]\s*$', "[project]`nsite_dir = ""_site"""
}
}
$docsConfigContent | Set-Content -Path $docsConfigTargetPath -Force
Write-Host "Build Config Type: $docsConfigFileName"
Show-FileContent -Path $docsConfigTargetPath
}
- name: Build documentation site with Zensical
working-directory: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/site
shell: pwsh
run: |
if (-not (Test-Path -Path 'zensical.toml')) {
throw "No documentation config file found in outputs/site. Expected zensical.toml."
}
$configFile = 'zensical.toml'
LogGroup 'Build docs - Zensical config content' {
Write-Host "Using config: $configFile"
Show-FileContent -Path $configFile
}
LogGroup 'Build docs - Zensical build' {
zensical build --config-file $configFile
}
LogGroup 'Build docs - verify output' {
if (Test-Path -Path '_site') {
if (Test-Path -Path '../../_site') {
Remove-Item -Path '../../_site' -Recurse -Force
}
Move-Item -Path '_site' -Destination '../../_site' -Force
}
if (-not (Test-Path -Path '../../_site')) {
throw "Expected Zensical output at ../../_site but it was not created."
}
}
- name: Inject shared site scripts
uses: ./_wf/.github/actions/Inject-SiteScripts
with:
SitePath: ${{ fromJson(inputs.Settings).WorkingDirectory }}/_site
WorkflowPath: _wf
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
name: github-pages
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/_site
retention-days: 1