name: Docs

on:
  pull_request:
  push:
    branches:
      - feature
    paths:
      - doc/**.md
  workflow_dispatch:
    branches:
      - feature

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

jobs:

  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

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

    - name: Build Docs
      working-directory: ./doc
      run: mdbook build --dest-dir Output/UCodeDocumentation
    
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        path: Output/UCodeDocumentation

  deploy:
    permissions:
      pages: write
      id-token: write

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4 
