name: Deploy dev-guide
on:
  push:
    branches:
      - master

env:
  MDBOOK_VERSION: 0.5.2

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6

    - name: Install mdbook
      run: |
        mkdir mdbook
        curl -Lf https://github.com/rust-lang/mdBook/releases/download/v${{ env.MDBOOK_VERSION }}/mdbook-v${{ env.MDBOOK_VERSION }}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
        echo `pwd`/mdbook >> $GITHUB_PATH

    - name: Build the book
      run: |
        cd dev-guide
        mdbook build
        mkdir out
        touch out/.nojekyll
        mv book out/dev-guide

    - name: Upload Artifact
      uses: actions/upload-pages-artifact@v3
      with:
        path: ./dev-guide/out

  deploy:
    needs: build

    permissions:
      pages: write
      id-token: write

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

    runs-on: ubuntu-latest
    steps:
      - id: deployment
        uses: actions/deploy-pages@v4
