Deploy to GitHub Pages

Add the following cicd.yml file to .github/workflows.

Then in the Repository Settings, go to Pages and set the Build and deployment Source setting to GitHub Actions. This way, when you push to main, GitHub will compile and deploy the site for you.

You can navigate to the MkDocs demo repository which contains this file. Make sure the watch the video!

cicd.yml
name: Deploy MkDocs site to GitHub Pages

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'

      - name: Install dependencies
        run: |
          pip install mkdocs mkdocs-material

      - name: Build MkDocs site
        run: |
          mkdocs build

      - name: Setup Pages
        uses: actions/configure-pages@v3

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: ./site

  deploy:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    needs: build

    permissions:
      pages: write
      id-token: write

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2

Comments