.github/workflows/docs.yml

name: Documentation
on:
  pull_request:
    paths: &inputs
      - website/**
      - rules/**
      - src/**
      - build.rs
      - Cargo.toml
      - Cargo.lock
      - indexes/**
      - python/**
      - skills/**
      - samples/**
      - py/**
      - README.md
      - pyproject.toml
      - mise.toml
      - .cargo/config.toml
      - .claude-plugin/plugin.json
      - mcp.json
      - licenses/**
      - LICENSE-*
      - .github/workflows/docs.yml
      - .github/scripts/check_ci_budget.py
  push:
    branches: [main]
    paths: *inputs
  schedule:
    - cron: "17 5 * * 1"
  workflow_dispatch:
permissions: {}
jobs:
  build:
    permissions:
      contents: read
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ${{ fromJSON('["self-hosted", "homelab"]') }}
    timeout-minutes: 12
    concurrency:
      group: docs-build-${{ github.event.pull_request.number || github.ref }}
      cancel-in-progress: ${{ github.event_name == 'pull_request' }}
    steps:
      - name: Start timer
        run: echo "START_EPOCH=$(date +%s)" >> "$GITHUB_ENV"
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          clean: false
      - run: |
          git clean -fd
          if [ -L target ]; then rm target; fi
          mkdir -p target
          echo "MBX_DISABLE=1" >> "$GITHUB_ENV"
          mise trust --quiet
          mise install --yes
          mise bin-paths >> "$GITHUB_PATH"
          mise env --dotenv >> "$GITHUB_ENV"
      - run: mise run docs
        env:
          MISE_TASK_RUN_AUTO_INSTALL: "false"
          XPD_NEWEST_LIBRARIES: ${{ github.event_name == 'schedule' && '1' || '' }}
      - name: Enforce Docs performance budget
        run: |
          RUNNER_ENVIRONMENT=self-hosted python3 .github/scripts/check_ci_budget.py --enforce --workflow docs \
            --start-epoch "$START_EPOCH" \
            --self-hosted-max-seconds 150 \
            --hosted-max-seconds 300 \
            --require-file ~/.cache/xpd/models/embeddinggemma-300M-Q8_0.gguf
      - name: Deploy docs to Cloudflare Workers
        if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && vars.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_API_TOKEN != ''
        working-directory: website
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_CI_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
        run: cf deploy ../site --force
      - name: Deploy docs preview to Cloudflare Workers
        if: github.event_name == 'pull_request' && vars.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_API_TOKEN != ''
        working-directory: website
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_CI_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: cf previews deploy ../site --preview-name "pr-${PR_NUMBER}"