Deploying Documentation to GitHub Pages¶
This guide explains how to deploy the MkDocs documentation to GitHub Pages.
Prerequisites¶
- Git repository on GitHub
- Python 3.8+ installed
- Write access to the repository
Deployment Options¶
Step 1: Install MkDocs
# Install MkDocs and dependencies
pip install -r requirements.txt
# Verify installation
mkdocs --version
Step 2: Build Documentation
Step 3: Deploy to GitHub Pages
# Deploy to gh-pages branch
mkdocs gh-deploy
# This will:
# 1. Build the documentation
# 2. Push to gh-pages branch
# 3. Make it available at https://yourusername.github.io/authentication_test
Step 4: Configure GitHub Pages
- Go to your repository on GitHub
- Click "Settings"
- Scroll to "Pages" section
- Under "Source", select:
- Branch:
gh-pages - Folder:
/ (root) - Click "Save"
Your documentation will be available at:
Step 1: Create Workflow File
Create .github/workflows/docs.yml:
name: Deploy Documentation
on:
push:
branches:
- main
paths:
- 'docs/**'
- 'mkdocs.yml'
- 'requirements.txt'
- '.github/workflows/docs.yml'
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Cache dependencies
uses: actions/cache@v3
with:
key: ${{ github.ref }}
path: .cache
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build and deploy
run: mkdocs gh-deploy --force
Step 2: Commit and Push
git add .github/workflows/docs.yml
git commit -m "Add GitHub Actions workflow for documentation"
git push origin main
Step 3: Verify Deployment
- Go to "Actions" tab in your repository
- Watch the workflow run
- Once complete, visit your documentation site
Customizing Deployment¶
Custom Domain¶
-
Create
docs/CNAMEfile: -
Configure DNS:
-
Add CNAME record pointing to
yourusername.github.io -
In GitHub Settings → Pages:
- Enter custom domain
- Enable "Enforce HTTPS"
Update mkdocs.yml¶
Local Development¶
Serve Locally¶
Visit: http://localhost:8000
Build Only¶
# Build without deploying
mkdocs build
# Build to custom directory
mkdocs build --site-dir custom_site
Clean Build¶
Troubleshooting¶
Build Fails¶
Check for errors:
Common issues:
- Missing dependencies: pip install -r requirements.txt
- Invalid YAML in mkdocs.yml
- Broken links in documentation
Deployment Fails¶
- Check GitHub Actions logs
- Verify permissions:
- Ensure gh-pages branch exists
Site Not Updating¶
- Clear browser cache
- Wait a few minutes for GitHub Pages to update
- Check GitHub Actions workflow completed successfully
- Verify gh-pages branch has new commits
404 Errors¶
- Check
site_urlin mkdocs.yml - Verify GitHub Pages is enabled
- Ensure gh-pages branch is selected as source
Best Practices¶
1. Version Control¶
Don't commit the site/ directory:
2. Documentation Structure¶
Keep documentation organized:
docs/
├── index.md
├── getting-started/
├── build/
├── keycloak/
├── api/
├── config/
├── troubleshooting/
└── development/
3. Regular Updates¶
Update documentation with code changes:
4. Review Before Deploy¶
Always review locally:
5. Use Branches¶
For major documentation changes:
git checkout -b docs/update-api-guide
# Make changes
git push origin docs/update-api-guide
# Create pull request
Monitoring¶
Search¶
MkDocs Material includes built-in search. No configuration needed.
Maintenance¶
Update Dependencies¶
# Update all dependencies
pip install --upgrade -r requirements.txt
# Update specific package
pip install --upgrade mkdocs-material