Skip to content

Instantly share code, notes, and snippets.

@Aveline-art
Last active April 2, 2022 05:06
Show Gist options
  • Save Aveline-art/d88f94bfe91a9937ee7ca70c0f85e204 to your computer and use it in GitHub Desktop.
Save Aveline-art/d88f94bfe91a9937ee7ca70c0f85e204 to your computer and use it in GitHub Desktop.

Is this your directory structure? Are you using Docker so you can avoid downloading MkDocs? Are you having a hard time getting MkDocs to create a docs/ folder inside of your root that is intergrated with gh-pages without jumping through some hoops?

├── app/
└── mkdocs/
     ├── <mkdocs files>
     ├── dockerfile
     ├── docker-compose.yml
     └── mkdocs.yml

Have no fear! Below is a GitHub action that will build your docs/ folder so that your MkDocs documentation will be built and ready as soon as your push your mkdocs file to your main repo!

Note: Please make sure that all dependencies are up-to-date before proceeding.

# Credit for code: https://github.com/mkdocs/mkdocs/discussions/2369#discussioncomment-625475
name: Build MkDocs site
on:
push:
branches:
- main
paths:
- "mkdocs/**/**.md"
- "mkdocs/mkdocs.yml"
workflow_dispatch:
jobs:
docs:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install mkdocs
uses: actions/setup-python@v3
- name: Publish docs
run: |
pip install --upgrade pip && pip install mkdocs
git config user.name 'github-actions[bot]' && git config user.email 'github-actions[bot]@users.noreply.github.com'
cd mkdocs
mkdocs build
- name: Commit docs
run: |
cd docs
cat > .nojekyll
git add -A
git commit -m "Deployed with mkdocs build"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment