From 4095963b0a39cb1fdd96b608fbd793b4df600d37 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 17 Oct 2024 00:32:57 +0200 Subject: [PATCH] Autogenerate documentation for settings --- docker/docs/builder/Dockerfile | 5 +++- docker/docs/builder/run.sh | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/docker/docs/builder/Dockerfile b/docker/docs/builder/Dockerfile index dd0ab925431..c9f700756da 100644 --- a/docker/docs/builder/Dockerfile +++ b/docker/docs/builder/Dockerfile @@ -9,7 +9,7 @@ RUN CGO_ENABLED=0 go install github.com/wjdp/htmltest@v${HTMLTEST_VERSION} \ # nodejs 17 prefers ipv6 and is broken in our environment FROM node:16-alpine -RUN apk add --no-cache git openssh bash +RUN apk add --no-cache git openssh bash curl # At this point we want to really update /opt/clickhouse-docs directory # So we reset the cache @@ -33,4 +33,7 @@ RUN mkdir /output_path \ COPY run.sh /run.sh COPY --from=htmltest-builder /usr/bin/htmltest /usr/bin/htmltest +# Install ClickHouse Local, which is used to auto-generate some doc pages. +RUN curl https://clickhouse.com/ | sh && ./clickhouse install -y + ENTRYPOINT ["/run.sh"] diff --git a/docker/docs/builder/run.sh b/docker/docs/builder/run.sh index d73adb5d279..10de24d21ac 100755 --- a/docker/docs/builder/run.sh +++ b/docker/docs/builder/run.sh @@ -21,6 +21,60 @@ do fi done +# Generate pages with settings + +ch -q " +WITH + +'/ClickHouse/docs/en/operations/settings/settings.md' AS doc_file, +'/ClickHouse/src/Core/Settings.cpp' AS cpp_file, + +settings_from_cpp AS +( + SELECT extract(line, 'M\(\w+, (\w+),') AS name + FROM file(cpp_file, LineAsString) + WHERE match(line, '^\s*M\(') +), + +main_content AS +( + SELECT format('## {} {}\n\nType: {}\n\nDefault value: {}\n\n{}\n\n', name, '{#'||name||'}', type, default, trim(BOTH '\n' FROM description)) + FROM system.settings WHERE name IN settings_from_cpp + ORDER BY name +), + +(SELECT extract(raw_blob, '(^(?:[^#]|#[^#])+)##') FROM file(doc_file, RawBLOB)) AS prefix + +SELECT prefix || (SELECT groupConcat(*) FROM main_content) +INTO OUTFILE '/opt/clickhouse-docs/docs/en/operations/settings/settings.md' TRUNCATE FORMAT LineAsString +" + +ch -q " +WITH + +'/ClickHouse/docs/en/operations/settings/settings-formats.md' AS doc_file, +'/ClickHouse/src/Core/FormatFactorySettingsDeclaration.h' AS cpp_file, + +settings_from_cpp AS +( + SELECT extract(line, 'M\(\w+, (\w+),') AS name + FROM file(cpp_file, LineAsString) + WHERE match(line, '^\s*M\(') +), + +main_content AS +( + SELECT format('## {} {}\n\nType: {}\n\nDefault value: {}\n\n{}\n\n', name, '{#'||name||'}', type, default, trim(BOTH '\n' FROM description)) + FROM system.settings WHERE name IN settings_from_cpp + ORDER BY name +), + +(SELECT extract(raw_blob, '(^(?:[^#]|#[^#])+)##') FROM file(doc_file, RawBLOB)) AS prefix + +SELECT prefix || (SELECT groupConcat(*) FROM main_content) +INTO OUTFILE '/opt/clickhouse-docs/docs/en/operations/settings/settings-formats.md' TRUNCATE FORMAT LineAsString +" + # Force build error on wrong symlinks sed -i '/onBrokenMarkdownLinks:/ s/ignore/error/g' docusaurus.config.js