.github/workflows/docs.yml

name: Documentation
on:
  pull_request:
  push:
    branches: [main]
  workflow_dispatch:
permissions: {}
jobs:
  build-and-deploy:
    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: 15
    concurrency:
      group: docs-build-${{ github.event.pull_request.number || github.ref }}
      cancel-in-progress: ${{ github.event_name == 'pull_request' }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          clean: false
      - name: Set up mise tools
        run: |
          git clean -fd
          mise trust --quiet
          mise install --yes
          mise bin-paths >> "$GITHUB_PATH"
          mise env --dotenv >> "$GITHUB_ENV"
      - name: Run CI checks and build static docs
        run: mise run ci
        env:
          MISE_TASK_RUN_AUTO_INSTALL: "false"
      - 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: apps/docs
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_CI_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
        run: cf deploy ./out --force
      - name: Deploy docs preview to Cloudflare Workers
        if: github.event_name == 'pull_request' && vars.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_API_TOKEN != ''
        working-directory: apps/docs
        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 ./out --preview-name "pr-${PR_NUMBER}"