Skip to content

fix: build site from zensical config #2

fix: build site from zensical config

fix: build site from zensical config #2

Workflow file for this run

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 site dependencies
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
pip install pyyaml
pip install tomli
- 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 mkdocs.yml from zensical.toml' {
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
$zensicalSourcePath = Join-Path -Path $rootPath -ChildPath '.github/zensical.toml'
if (-not (Test-Path -Path $zensicalSourcePath)) {
throw "Zensical source file not found at expected location: .github/zensical.toml"
}
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
Write-Host "Zensical Source Path: $zensicalSourcePath"
Write-Host "Mkdocs Target Path: $mkdocsTargetPath"
$zensicalContent = Get-Content -Path $zensicalSourcePath -Raw
$zensicalContent = $zensicalContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
$zensicalContent = $zensicalContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
$zensicalInputPath = Join-Path -Path $SiteOutputPath -ChildPath 'zensical.toml'
$zensicalContent | Set-Content -Path $zensicalInputPath -Force
python3 -c @'
import pathlib

Check failure on line 137 in .github/workflows/Build-Site.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/Build-Site.yml

Invalid workflow file

You have an error in your yaml syntax on line 137
import yaml
try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib
source_path = pathlib.Path('outputs/site/zensical.toml')
target_path = pathlib.Path('outputs/site/mkdocs.yml')
with source_path.open('rb') as source_file:
zensical = tomllib.load(source_file)
project = zensical.get('project', {})
theme = dict(project.get('theme', {}))
theme.pop('variant', None)
theme = {'name': 'material', **theme}
markdown_extensions = []
for name, value in project.get('markdown_extensions', {}).items():
if value:
markdown_extensions.append({name: value})
else:
markdown_extensions.append(name)
mkdocs = {
'site_name': project.get('site_name'),
'repo_name': project.get('repo_name'),
'repo_url': project.get('repo_url'),
'theme': theme,
'plugins': project.get('plugins', ['search']),
'markdown_extensions': markdown_extensions,
}
if 'extra' in project:
mkdocs['extra'] = project['extra']
with target_path.open('w', encoding='utf-8') as target_file:
yaml.safe_dump(mkdocs, target_file, sort_keys=False, allow_unicode=True)
'@
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@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
name: github-pages
path: ${{ fromJson(inputs.Settings).WorkingDirectory }}/_site
retention-days: 1