name: Docs Site

on:
  # Publish the guide whenever a release is created (release-plz publishes a
  # GitHub Release for each version). Keeps the site aligned with crates.io.
  release:
    types: [published]
  workflow_dispatch:

permissions:
  contents: read

# Allow only one concurrent deployment; do not cancel in-progress runs so a
# deploy always completes.
concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    name: Build mdbook
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'lnivva' }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v7
        with:
          persist-credentials: false

      - name: Install mdbook
        uses: peaceiris/actions-mdbook@v2
        with:
          mdbook-version: '0.5.4'

      - name: Build book
        run: mdbook build docs

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

  deploy:
    name: Deploy to GitHub Pages
    needs: build
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'lnivva' }}
    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@v4
