From 947b99e8ebaa81e9c8ee9b0f3e247d8d329041ad Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 28 Nov 2024 15:43:36 +0800 Subject: Add Table of Contents check to CI, and bot script to regenerate (#5618) * Sort filenames when generating table of contents The order of EnumerateFiles is unspecified * Add build table of contents bash script * Add toc checking to CI * Add --check-only option to toc checking * regenerate ToC --- docs/build_toc.sh | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100755 docs/build_toc.sh (limited to 'docs') diff --git a/docs/build_toc.sh b/docs/build_toc.sh new file mode 100755 index 000000000..9c158d6a2 --- /dev/null +++ b/docs/build_toc.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +set -e + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +project_root="$(dirname "$script_dir")" +check_only=0 + +show_help() { + me=$(basename "$0") + cat <] [--check-only] + +Options: + --help Show this help message + --source Path to project root directory (defaults to parent of the script directory) + --check-only Check if TOC needs updating, exit 1 if changes needed +EOF +} + +while [[ "$#" -gt 0 ]]; do + case $1 in + -h | --help) + show_help + exit 0 + ;; + --source) + project_root="$2" + shift + ;; + --check-only) + check_only=1 + ;; + *) + echo "unrecognized argument: $1" >&2 + show_help >&2 + exit 1 + ;; + esac + shift +done + +missing_bin=0 + +require_bin() { + local name="$1" + if ! command -v "$name" &>/dev/null; then + echo "This script needs $name, but it isn't in \$PATH" >&2 + missing_bin=1 + return + fi +} + +require_bin "mcs" +require_bin "mono" + +if [ "$missing_bin" -eq 1 ]; then + exit 1 +fi + +temp_dir=$(mktemp -d) +trap 'rm -rf "$temp_dir"' EXIT + +cd "$project_root/docs" || exit 1 + +cat >"$temp_dir/temp_program.cs" <&2 + exit 1 +fi + +for dir in "user-guide" "gfx-user-guide"; do + if [ -d "$script_dir/$dir" ]; then + if [ "$check_only" -eq 1 ]; then + # Ensure working directory is clean + if ! git diff --quiet "$script_dir/$dir/toc.html" 2>/dev/null; then + echo "Working directory not clean, cannot check TOC" >&2 + exit 1 + fi + fi + + if ! mono "$temp_dir/toc-builder.exe" "$script_dir/$dir"; then + echo "TOC generation failed for $dir" >&2 + exit 1 + fi + + if [ "$check_only" -eq 1 ]; then + if ! git diff --quiet "$script_dir/$dir/toc.html" 2>/dev/null; then + git diff --color "$script_dir/$dir/toc.html" + git checkout -- "$script_dir/$dir/toc.html" 2>/dev/null + exit 1 + fi + fi + else + echo "Directory $dir not found" >&2 + fi +done -- cgit v1.2.3