name: Build documentation

on:
  push:
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Install software
        run: |
          sudo apt-get update
          sudo apt-get install -y doxygen make rsync clang-19 clang-tools-19 bear llvm-19
          sudo ln -sf /usr/bin/clang-19 /usr/bin/clang
          sudo ln -sf /usr/bin/clang-doc-19 /usr/bin/clang-doc
          sudo ln -sf /usr/bin/llvm-ar-19 /usr/bin/llvm-ar

      - name: Set up python3
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'

      - name: Install mkdocs
        run: |
          pip install --upgrade pip
          pip install mkdocs mkdocs-material pymdown-extensions

      - name: Build
        run: ./aux/docs.sh

      - name: Deploy
        env:
          SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
          REMOTE_IP: ${{ vars.DEPLOY_REMOTE_IP }}
        run: |
          mkdir -p ~/.ssh
          echo "$SSH_KEY" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -H "$REMOTE_IP" >> ~/.ssh/known_hosts
          chmod -R 777 site
          rsync -az --delete site/ webuser@"$REMOTE_IP":/home/webuser/mop/
