Publish MkDocs Documentation #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish MkDocs Documentation | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to deploy (e.g. 20.0)' | |
required: true | |
default: '20.0' | |
type: string | |
update_latest: | |
description: 'Update this as latest version?' | |
required: true | |
default: true | |
type: boolean | |
permissions: | |
contents: write | |
pages: write | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Required for mike to work properly | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Set up Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install \ | |
mike \ | |
mkdocs-material \ | |
mkdocs-macros-plugin \ | |
mkdocs-monorepo-plugin \ | |
mkdocs-site-urls \ | |
mkdocs-caption \ | |
markdown-tables-extended | |
- name: Get Git Info | |
id: git-info | |
run: | | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
HASH=$(git rev-parse --short HEAD) | |
echo "GIT_INFO=${BRANCH}:${HASH}" >> $GITHUB_OUTPUT | |
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
echo "CURRENT_YEAR=$(date +'%Y')" >> $GITHUB_OUTPUT | |
- name: Substitute env variables in mkdocs.yml | |
env: | |
GIT_INFO: ${{ steps.git-info.outputs.GIT_INFO }} | |
BUILD_DATE: ${{ steps.git-info.outputs.DATE }} | |
CURRENT_YEAR: ${{ steps.git-info.outputs.CURRENT_YEAR }} | |
run: | | |
# Create backup | |
cp mkdocs.yml mkdocs.yml.bak | |
# Substitute variables | |
envsubst '$BUILD_DATE $GIT_INFO $CURRENT_YEAR' < mkdocs.yml.bak > mkdocs.yml | |
# Display substituted content for debugging | |
echo "--- Checking substituted content ---" | |
cat mkdocs.yml | grep -A5 copyright | |
- name: Deploy documentation | |
run: | | |
if [ "${{ inputs.update_latest }}" = "true" ]; then | |
mike deploy --push ${{ inputs.version }} latest | |
else | |
mike deploy --push ${{ inputs.version }} | |
fi |