name: Docs

on:
  push:
    branches: ["main"]
    paths:
      - "docs/**"
      - ".github/workflows/docs.yml"
  workflow_dispatch:

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

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

jobs:
  build:
    name: Build book
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

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

      - name: Build
        run: mdbook build docs

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: docs/book

  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@v5
