name: Deploy Docs

on:
  push:
    branches: [main]
    paths:
      - 'docs/src/**'
      - 'docs/build/**'
      - 'docs/build.sh'
      - '.github/workflows/deploy-docs.yml'

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

concurrency:
  group: pages
  cancel-in-progress: true

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

      - name: Install Pandoc
        uses: pandoc/actions/setup@v1

      - name: Build docs
        run: bash docs/build.sh

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: docs/out/html

  deploy:
    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@v4
