name: Docs

on:
  push:
    branches: [main]
    paths:
      - 'docs/**'
      - '.github/workflows/docs.yml'
  workflow_dispatch:

# Allow GITHUB_TOKEN to deploy to GitHub Pages.
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment, skipping runs queued between the run
# in-progress and latest queued. Do not cancel in-progress runs.
concurrency:
  group: pages
  cancel-in-progress: false

env:
  HUGO_VERSION: 0.162.0

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Install Hugo CLI
        run: |
          wget -O ${{ runner.temp }}/hugo.deb \
            https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
          sudo dpkg -i ${{ runner.temp }}/hugo.deb

      - uses: actions/checkout@v6
        with:
          submodules: false
          lfs: true  # PNGs are Git LFS objects; without this they deploy as pointer files
          fetch-depth: 0  # enableGitInfo needs full history

      - name: Setup Go
        uses: actions/setup-go@v6
        with:
          go-version: '1.21'

      - name: Setup Pages
        id: pages
        uses: actions/configure-pages@v6

      - name: Build
        run: hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
        working-directory: docs

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: docs/public

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