Skip to content

Commit 0a5e46f

Browse files
🚀 [Feature]: Publish module docs using Material on MkDocs (#34)
## Description - Uses newest version of Build-PSModule to build the docs folder for creating the site. - Publish docs to GitHub Pages using MkDocs. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 059fd97 commit 0a5e46f

File tree

7 files changed

+250
-15
lines changed

7 files changed

+250
-15
lines changed

.github/workflows/Workflow-Test-Default.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ permissions:
1212
contents: write
1313
pull-requests: write
1414
statuses: write
15+
pages: write
16+
id-token: write
1517

1618
jobs:
1719
WorkflowTestDefault:

.github/workflows/Workflow-Test-WithManifest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ permissions:
1212
contents: write
1313
pull-requests: write
1414
statuses: write
15+
pages: write
16+
id-token: write
1517

1618
jobs:
1719
WorkflowTestWithManifest:

.github/workflows/workflow.yml

Lines changed: 151 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ on:
2626
description: The path to the output directory for the documentation.
2727
required: false
2828
default: outputs/docs
29+
SiteOutputPath:
30+
type: string
31+
description: The path to the output directory for the site.
32+
required: false
33+
default: outputs/site
2934
SkipTests:
3035
type: string
3136
description: Defines what types of tests to skip. Allowed values are 'All', 'SourceCode', 'Module', 'None', 'macOS', 'Windows', 'Linux', 'Desktop', 'Core'.
@@ -45,14 +50,19 @@ on:
4550
description: Whether the version is a prerelease.
4651
required: false
4752
default: false
53+
PublishDocs:
54+
type: boolean
55+
description: Whether to publish the documentation using MkDocs and GitHub Pages.
56+
required: false
57+
default: true
4858

4959
env:
5060
GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication
5161

5262
permissions:
53-
contents: write
54-
pull-requests: write
55-
statuses: write
63+
contents: write # to checkout the repo and create releases on the repo
64+
pull-requests: write # to write comments to PRs
65+
statuses: write # to update the status of the workflow from linter
5666

5767
jobs:
5868
TestSourceCode-pwsh-ubuntu-latest:
@@ -533,10 +543,9 @@ jobs:
533543

534544
PublishModule:
535545
name: Publish module
536-
if: ${{ needs.TestModuleStatus.result == 'success' && needs.LintDocs.result == 'success' && !cancelled() && github.event_name == 'pull_request' }}
546+
if: ${{ needs.TestModuleStatus.result == 'success' && !cancelled() && github.event_name == 'pull_request' }}
537547
needs:
538548
- TestModuleStatus
539-
- LintDocs
540549
runs-on: ubuntu-latest
541550
steps:
542551
- name: Checkout Code
@@ -554,17 +563,147 @@ jobs:
554563
name: module
555564
path: ${{ inputs.ModulesOutputPath }}
556565

557-
- name: Download docs artifact
558-
uses: actions/download-artifact@v4
559-
with:
560-
name: docs
561-
path: ${{ inputs.DocsOutputPath }}
562-
563566
- name: Publish module
564567
uses: PSModule/Publish-PSModule@v1
565568
with:
566569
Name: ${{ inputs.Name }}
567570
ModulePath: ${{ inputs.ModulesOutputPath }}
568-
DocsPath: ${{ inputs.DocsOutputPath }}
569571
APIKey: ${{ secrets.APIKEY }}
570572
WhatIf: ${{ inputs.TestProcess }}
573+
574+
BuildSite:
575+
name: Build Site
576+
if: ${{ inputs.PublishDocs && needs.LintDocs.result == 'success' && !cancelled() }}
577+
needs: LintDocs
578+
runs-on: ubuntu-latest
579+
steps:
580+
- name: Checkout Code
581+
uses: actions/checkout@v4
582+
with:
583+
fetch-depth: 0
584+
ref: ${{ github.event.pull_request.head.sha }}
585+
586+
- name: Initialize environment
587+
uses: PSModule/Initialize-PSModule@v1
588+
with:
589+
Version: ${{ inputs.Version }}
590+
Prerelease: ${{ inputs.Prerelease }}
591+
592+
- name: Download docs artifact
593+
uses: actions/download-artifact@v4
594+
with:
595+
name: docs
596+
path: ${{ inputs.DocsOutputPath }}
597+
598+
- name: Debug File system
599+
shell: pwsh
600+
run: |
601+
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse | Select-Object -ExpandProperty FullName | Sort-Object
602+
603+
- name: Debug Env vars
604+
shell: pwsh
605+
run: |
606+
Get-ChildItem env: | Format-Table
607+
608+
- uses: actions/configure-pages@v5
609+
610+
- name: Install mkdoks-material
611+
shell: pwsh
612+
run: |
613+
pip install mkdocs-material
614+
pip install mkdocs-git-authors-plugin
615+
pip install mkdocs-git-revision-date-localized-plugin
616+
pip install mkdocs-git-committers-plugin-2
617+
618+
- name: Run Script
619+
shell: pwsh
620+
run: |
621+
$ModuleName = '${{ inputs.Name }}'
622+
623+
if (-not $ModuleName) {
624+
$ModuleName = $env:GITHUB_REPOSITORY -replace '.+/'
625+
}
626+
Write-Verbose "Module name: $ModuleName"
627+
628+
$ModuleSourcePath = Join-Path (Get-Location) -ChildPath '${{ inputs.Path }}'
629+
$DocsOutputPath = Join-Path (Get-Location) -ChildPath "${{ inputs.DocsOutputPath }}/$ModuleName"
630+
$SiteOutputPath = Join-Path (Get-Location) -ChildPath '${{ inputs.SiteOutputPath }}'
631+
632+
$functionDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Functions'
633+
$functionDocsFolder = New-Item -Path $functionDocsFolderPath -ItemType Directory -Force
634+
Get-ChildItem -Path $DocsOutputPath -Recurse -Force -Include '*.md' | Copy-Item -Destination $functionDocsFolder -Recurse -Force
635+
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
636+
$fileName = $_.Name
637+
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
638+
Start-LogGroup " - [$fileName] - [$hash]"
639+
Show-FileContent -Path $_
640+
Stop-LogGroup
641+
}
642+
643+
Start-LogGroup 'Build docs - Process about topics'
644+
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
645+
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
646+
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
647+
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
648+
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
649+
Stop-LogGroup
650+
651+
Start-LogGroup 'Build docs - Copy icon to assets'
652+
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
653+
$null = New-Item -Path $assetsFolderPath -ItemType Directory -Force
654+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
655+
$iconPath = Join-Path -Path $rootPath -ChildPath 'icon\icon.png'
656+
Copy-Item -Path $iconPath -Destination $assetsFolderPath -Force -Verbose
657+
658+
Start-LogGroup 'Build docs - Copy readme.md'
659+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
660+
$readmePath = Join-Path -Path $rootPath -ChildPath 'README.md'
661+
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
662+
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
663+
Stop-LogGroup
664+
665+
Start-LogGroup 'Build docs - Create mkdocs.yml'
666+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
667+
# This should be moved to an action so that we can use a default one, and not have to copy it from the repo.
668+
$mkdocsSourcePath = Join-Path -Path $rootPath -ChildPath 'mkdocs.yml'
669+
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
670+
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
671+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
672+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
673+
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
674+
Show-FileContent -Path $mkdocsTargetPath
675+
Stop-LogGroup
676+
677+
- name: Debug File system
678+
shell: pwsh
679+
run: |
680+
Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse | Select-Object -ExpandProperty FullName | Sort-Object
681+
682+
- name: Build mkdocs-material project
683+
working-directory: ${{ inputs.SiteOutputPath }}
684+
shell: pwsh
685+
run: |
686+
Start-LogGroup 'Build docs - mkdocs build - content'
687+
Show-FileContent -Path mkdocs.yml
688+
Stop-LogGroup
689+
Start-LogGroup 'Build docs - mkdocs build'
690+
mkdocs build --config-file mkdocs.yml --site-dir ${{ github.workspace }}/_site
691+
Stop-LogGroup
692+
693+
- uses: actions/upload-pages-artifact@v3
694+
695+
PublishSite:
696+
name: Publish documentation
697+
if: ${{ inputs.PublishDocs && needs.BuildSite.result == 'success' && !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.merged == true }}
698+
needs: BuildSite
699+
permissions:
700+
pages: write # to deploy to Pages
701+
id-token: write # to verify the deployment originates from an appropriate source
702+
environment:
703+
name: github-pages
704+
url: ${{ steps.deployment.outputs.page_url }}
705+
runs-on: ubuntu-latest
706+
steps:
707+
- name: Deploy to GitHub Pages
708+
id: deployment
709+
uses: actions/deploy-pages@v4

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
| `Path` | `string` | The path to the source code of the module. | `false` | `src` |
7474
| `ModulesOutputPath` | `string` | The path to the output directory for the modules. | `false` | `outputs/modules` |
7575
| `DocsOutputPath` | `string` | The path to the output directory for the documentation. | `false` | `outputs/docs` |
76+
| `PublishDocs` | `boolean` | Whether to publish the documentation using MkDocs and GitHub Pages. | `false` | `true` |
77+
| `SiteOutputPath` | `string` | The path to the output directory for the site. | `false` | `outputs/site` |
7678
| `SkipTests` | `string` | Defines what types of tests to skip. Allowed values are 'All', 'SourceCode', 'Module', 'None', 'macOS', 'Windows', 'Linux', 'Desktop', 'Core'. | false | `None` |
7779
| `TestProcess` | `boolean` | Whether to test the process. | false | `false` |
7880

@@ -93,11 +95,23 @@ If running the action in a restrictive mode, the following permissions needs to
9395

9496
```yaml
9597
permissions:
96-
contents: write # Required to create releases
97-
pull-requests: write # Required to create comments on the PRs
98-
statuses: write # Required to update the status of the PRs from the linter
98+
contents: write # Create releases
99+
pull-requests: write # Create comments on the PRs
100+
statuses: write # Update the status of the PRs from the linter
99101
```
100102
103+
### Publishing to GitHub Pages
104+
105+
To publish the documentation to GitHub Pages, the action requires the following permissions:
106+
107+
```yaml
108+
permissions:
109+
pages: write # Deploy to Pages
110+
id-token: write # Verify the deployment originates from an appropriate source
111+
```
112+
113+
For more info see [Deploy GitHub Pages site](https://github.com/marketplace/actions/deploy-github-pages-site).
114+
101115
## Compatibility
102116
103117
The action is compatible with the following configurations:

tests/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Test module
2+
3+
This is a test readme.

tests/icon/icon.png

5.74 KB
Loading

tests/mkdocs.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
site_name: -{{ REPO_NAME }}-
2+
theme:
3+
name: material
4+
language: en
5+
font:
6+
text: Roboto
7+
code: Sono
8+
logo: Assets/icon.png
9+
favicon: Assets/icon.png
10+
palette:
11+
# Palette toggle for automatic mode
12+
- media: "(prefers-color-scheme)"
13+
toggle:
14+
icon: material/link
15+
name: Switch to dark mode
16+
# Palette toggle for dark mode
17+
- media: '(prefers-color-scheme: dark)'
18+
scheme: slate
19+
toggle:
20+
primary: black
21+
accent: green
22+
icon: material/toggle-switch-off-outline
23+
name: Switch to light mode
24+
# Palette toggle for light mode
25+
- media: '(prefers-color-scheme: light)'
26+
scheme: default
27+
toggle:
28+
primary: indigo
29+
accent: green
30+
icon: material/toggle-switch
31+
name: Switch to system preference
32+
icon:
33+
repo: material/github
34+
features:
35+
- navigation.instant
36+
- navigation.instant.progress
37+
- navigation.indexes
38+
- navigation.top
39+
- navigation.tracking
40+
- navigation.expand
41+
- search.suggest
42+
- search.highlight
43+
44+
repo_name: -{{ REPO_OWNER }}-/-{{ REPO_NAME }}-
45+
repo_url: https://github.com/-{{ REPO_OWNER }}-/-{{ REPO_NAME }}-
46+
47+
plugins:
48+
- search
49+
50+
markdown_extensions:
51+
- toc:
52+
permalink: true # Adds a link icon to headings
53+
- attr_list
54+
- admonition
55+
- md_in_html
56+
- pymdownx.details # Enables collapsible admonitions
57+
58+
extra:
59+
social:
60+
- icon: fontawesome/brands/discord
61+
link: https://discord.gg/jedJWCPAhD
62+
name: -{{ REPO_OWNER }}- on Discord
63+
- icon: fontawesome/brands/github
64+
link: https://github.com/-{{ REPO_OWNER }}-/
65+
name: -{{ REPO_OWNER }}- on GitHub
66+
consent:
67+
title: Cookie consent
68+
description: >-
69+
We use cookies to recognize your repeated visits and preferences, as well
70+
as to measure the effectiveness of our documentation and whether users
71+
find what they're searching for. With your consent, you're helping us to
72+
make our documentation better.
73+
actions:
74+
- accept
75+
- reject

0 commit comments

Comments
 (0)