|
| 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 |
0 commit comments