name: Deploy Documentation

on:
  push:
    branches:
      - main
    paths:
      - 'book/**'
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    name: Build mdbook
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install mdbook
        uses: taiki-e/install-action@v2
        with:
          tool: mdbook

      - name: Build book
        run: mdbook build book

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: book/build

  deploy:
    name: Deploy to GitHub Pages
    needs: build
    runs-on: ubuntu-latest

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

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