Deploy Documentation to GitHub Pages¶
Set up automatic documentation deployment to GitHub Pages using GitHub Actions.
Prerequisites¶
- Repository hosted on GitHub
- Write access to repository settings
Step 1: Enable GitHub Pages¶
- Go to your repository on GitHub
- Navigate to Settings → Pages
- Under Build and deployment:
- Source: Select "GitHub Actions"
That's it! No need to select a branch or folder.
Step 2: Verify Workflow File¶
The repository includes .github/workflows/docs.yml which:
- Triggers on pushes to
mainbranch (when docs files change) - Can be manually triggered via workflow_dispatch
- Uses Makefile targets for consistency:
make py-setup- Install dependenciesmake docs-build-strict- Build docs (fails on warnings)
Step 3: Push to Main Branch¶
git add .github/workflows/docs.yml
git commit -m "Add GitHub Pages deployment workflow"
git push origin main
Step 4: Monitor Deployment¶
- Go to Actions tab in your repository
- Watch the "Deploy Documentation" workflow run
- Once complete, your docs are live!
Accessing Your Documentation¶
Your documentation will be available at:
For example:
Workflow Details¶
Trigger Conditions¶
The workflow runs when:
- Files in
docs/change mkdocs.ymlis modifiedREADME.md.j2orscripts/generate_readme.pychange- Workflow file itself is modified
- Manually triggered
Build Process¶
jobs:
build:
- Install Python 3.12
- Install uv
- Install dependencies (make py-setup)
- Build docs in strict mode (make docs-build-strict)
- Upload site artifact
deploy:
- Deploy to GitHub Pages
Strict Mode¶
The workflow uses make docs-build-strict which:
- Fails build on warnings
- Catches broken links
- Ensures documentation quality
- Validates all references
Troubleshooting¶
Build Fails on Warnings¶
The workflow uses strict mode. Fix all warnings before merging:
Common warnings: - Broken internal links - Missing images - Unrecognized relative links
Permissions Error¶
If deployment fails with permissions error:
- Go to Settings → Actions → General
- Under "Workflow permissions":
- Select "Read and write permissions"
- Check "Allow GitHub Actions to create and approve pull requests"
- Save changes
Custom Domain¶
To use a custom domain:
- Go to Settings → Pages
- Enter your custom domain under "Custom domain"
- Add a
CNAMEfile to yourdocs/directory:
Advanced: Versioned Documentation¶
The Makefile includes make docs-deploy which uses mike for versioned docs:
This creates version tags like:
- https://example.github.io/project/0.5.0/
- https://example.github.io/project/latest/ (alias)
To use versioned docs in CI:
- Generate a deploy key or use
GITHUB_TOKEN - Update workflow to use
make docs-deploy - Configure mike version strategy
Manual Deployment¶
To deploy manually:
# Build docs
make docs-build-strict
# Deploy using gh-pages branch (if not using Actions)
uv run mkdocs gh-deploy
Local Testing¶
Test the deployment process locally:
Open http://localhost:8000 to preview.
Workflow Configuration¶
The workflow file at .github/workflows/docs.yml:
name: Deploy Documentation
on:
push:
branches:
- main
paths:
- 'docs/**'
- 'mkdocs.yml'
- 'README.md.j2'
- 'scripts/generate_readme.py'
- '.github/workflows/docs.yml'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- run: make py-setup
- run: make docs-build-strict
- uses: actions/upload-pages-artifact@v3
with:
path: ./site
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/deploy-pages@v4
id: deployment
Next Steps¶
- Basic Usage - Publishing workflow
- Contributing - How to contribute to docs
- Configuration Reference - MkDocs config