-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (130 loc) · 6.8 KB
/
Build-Site.yml
File metadata and controls
155 lines (130 loc) · 6.8 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
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Install-PSModuleHelpers
uses: PSModule/Install-PSModuleHelpers@ed79b6e3aa8c9cd3d30ab2bf02ea6bd4687b9c74 # v1.0.7
- name: Download docs artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: docs
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/docs
- name: Install mkdocs-material
shell: pwsh
run: |
pip install mkdocs-material
pip install mkdocs-git-authors-plugin
pip install mkdocs-git-revision-date-localized-plugin
pip install mkdocs-git-committers-plugin-2
- name: Structure site
uses: PSModule/GitHub-Script@0097f3bbe3f413f3b577b9bcc600727b0ca3201a # v1.7.10
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 mkdocs.yml' {
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
$possiblePaths = @(
'.github/mkdocs.yml',
'docs/mkdocs.yml',
'mkdocs.yml'
)
$mkdocsSourcePath = $null
foreach ($path in $possiblePaths) {
$candidatePath = Join-Path -Path $rootPath -ChildPath $path
if (Test-Path -Path $candidatePath) {
$mkdocsSourcePath = $candidatePath
break
}
}
if (-not $mkdocsSourcePath) {
throw "Mkdocs source file not found in any of the expected locations: $($possiblePaths -join ', ')"
}
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
Write-Host "Mkdocs Source Path: $mkdocsSourcePath"
Write-Host "Mkdocs Target Path: $mkdocsTargetPath"
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
Show-FileContent -Path $mkdocsTargetPath
}
- name: Build mkdocs-material project
working-directory: ${{ fromJson(inputs.Settings).WorkingDirectory }}/outputs/site
shell: pwsh
run: |
LogGroup 'Build docs - mkdocs build - content' {
Show-FileContent -Path mkdocs.yml
}
LogGroup 'Build docs - mkdocs build' {
mkdocs build --config-file mkdocs.yml --site-dir ../../_site
}
- uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
name: github-pages
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/_site
retention-days: 1