| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: AGPL-3.0-or-later |
| 3 | # |
| 4 | # Build the public docs site and sync it to the Spaces bucket |
| 5 | # that Caddy serves docs.shithub.sh from. |
| 6 | # |
| 7 | # Run from CI on every push to main, or from an operator's |
| 8 | # workstation as a one-off. Idempotent: rclone sync only touches |
| 9 | # changed files. |
| 10 | |
| 11 | set -euo pipefail |
| 12 | |
| 13 | ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 14 | cd "$ROOT" |
| 15 | |
| 16 | BUCKET="${SHITHUB_DOCS_BUCKET:-spaces-docs:shithub-docs}" |
| 17 | |
| 18 | if ! command -v mdbook >/dev/null 2>&1; then |
| 19 | echo "fatal: mdbook not on PATH; install from https://rust-lang.github.io/mdBook/" >&2 |
| 20 | exit 2 |
| 21 | fi |
| 22 | |
| 23 | # Build into the configured build-dir from book.toml (build/docs/). |
| 24 | echo "building docs..." |
| 25 | cd docs/public && mdbook build && cd "$ROOT" |
| 26 | |
| 27 | if [[ ! -d build/docs ]]; then |
| 28 | echo "fatal: mdbook build did not produce build/docs/" >&2 |
| 29 | exit 2 |
| 30 | fi |
| 31 | |
| 32 | echo "syncing to $BUCKET..." |
| 33 | rclone --config /root/.config/rclone/rclone.conf \ |
| 34 | sync --transfers 8 --checkers 16 \ |
| 35 | build/docs "$BUCKET" |
| 36 | |
| 37 | echo "docs sync complete" |