# Workflow for building and deploying a mdBook site to GitHub Pages
name: GitHub Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: [book, master]

  # Also runs on PR
  pull_request:

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: pages
  cancel-in-progress: true

jobs:
  # Build job
  build-book:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup mdBook
      uses: peaceiris/actions-mdbook@v2
      with:
        mdbook-version: 0.4.28

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

    - name: Download assets
      run: |
        cd book/
        mdbook-admonish install

    - name: Build book
      run: mdbook build book

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

  # Deployment job
  deploy:
    if: github.event_name != 'pull_request'
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: [build-book]
    steps:
    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v4
