name: Sphinx build

on:  # yamllint disable-line rule:truthy
  push:
    branches:
      - master
  workflow_dispatch:

permissions:
  contents: read

jobs:
  sphinx-build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
      pages: write
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

      - name: Install uv
        uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
        with:
          python-version: "3.10"

      - name: Install dependencies
        run: |
          sudo apt-get update; sudo apt-get install libkrb5-dev gcc

      - name: Build HTML
        run: make
        working-directory: ./doc

      - name: Upload artifacts
        uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
        with:
          name: html-docs
          path: ./doc/html/

      - name: Deploy Master Docs to GitHub Pages
        if: ${{ github.ref == 'refs/heads/master' }}
        uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./doc/html
          publish_branch: gh-pages
          keep_files: false
