# Build Sphinx docs and publish to GitHub Pages (rtrash.rgoswami.me).
name: docs

on:
  push:
    branches: [main]
    paths:
      - "docs/**"
      - "README.md"
      - ".github/workflows/docs.yml"
  pull_request:
    paths:
      - "docs/**"
  workflow_dispatch:

permissions:
  contents: write

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install pandoc
        run: sudo apt-get update && sudo apt-get install -y pandoc

      - name: Build site
        run: |
          ./docs/build.sh
          touch docs/build/.nojekyll
          echo rtrash.rgoswami.me > docs/build/CNAME

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: documentation
          path: docs/build

      - name: Deploy to GitHub Pages
        if: >-
          (github.event_name == 'push' && github.ref_name == 'main') ||
          github.event_name == 'workflow_dispatch'
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: docs/build
          cname: rtrash.rgoswami.me
          force_orphan: true
