From 9b0b991af96874f2f655ae0b79cbb8c6f3406d49 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 17 Sep 2023 13:50:33 +0200 Subject: [PATCH] Check hooks index in CI --- .github/workflows/dynamic.yml | 10 ++++- scripts/update_docs_index.sh | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 scripts/update_docs_index.sh diff --git a/.github/workflows/dynamic.yml b/.github/workflows/dynamic.yml index f169f0a..bd5a273 100644 --- a/.github/workflows/dynamic.yml +++ b/.github/workflows/dynamic.yml @@ -48,4 +48,12 @@ jobs: run: | gem install bundler bundle install --jobs 4 --retry 3 - ./scripts/hooks.sh \ No newline at end of file + ./scripts/hooks.sh + doc-index: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Check doc index up to date + run: | + ./scripts/update_docs_index.sh \ No newline at end of file diff --git a/scripts/update_docs_index.sh b/scripts/update_docs_index.sh new file mode 100755 index 0000000..dfc0cd9 --- /dev/null +++ b/scripts/update_docs_index.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +if [ ! -d spec ] +then + echo "Error: spec folder not found" + echo " run this script from the root of repo" + exit 1 +fi + +tmpdir=scripts/tmp +mkdir -p scripts/tmp + +arg_generate_docs=0 + +for arg in "$@" +do + if [ "$arg" == "--fix" ] || [ "$arg" == "--generate-docs" ] + then + arg_generate_docs=1 + else + echo "usage: ./scripts/update_docs_index.sh [--fix]" + exit 1 + fi +done + +function print_hooks() { + local version="$1" + local hook + local hook_slug + while read -r hook + do + hook_slug="${hook%%(*}" + echo "" + echo "[#$hook](classes/TeeworldsClient.md#$hook_slug)" + done < <(grep '###' "docs/$version/classes/TeeworldsClient.md" | cut -d'#' -f5) +} + +function gen_doc_index() { + local version="$1" + local index_file="docs/$version/README.md" + if [ ! -f "$index_file" ] + then + echo "Error: missing index file $index_file" + exit 1 + fi + local tmpfile="$tmpdir/README.md" + { + awk '1;/TeeworldsClient/{exit}' "$index_file" + print_hooks "$version" + } > "$tmpfile" + if [ "$arg_generate_docs" == "1" ] + then + mv "$tmpfile" "$index_file" + return + fi + local diff="$(diff "$tmpfile" "$index_file")" + if [ "$diff" != "" ] + then + echo "Error: documentation index is not up to date" + echo " to fix this run ./scripts/update_docs_index.sh --fix" + echo "" + echo "$diff" + exit 1 + fi +} + +function main() { + local version + version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)" + if [ "$version" == "" ] + then + echo "Error: failed to get library version" + exit 1 + fi + gen_doc_index "$version" +} + +main