Skip to content

Commit

Permalink
Merge pull request #2714 from ClickHouse/build-settings
Browse files Browse the repository at this point in the history
Autogenerate settings
  • Loading branch information
justindeguzman authored Oct 18, 2024
2 parents b23bece + 21331d0 commit bd97095
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ sidebar_links.txt
orphaned_pages.txt
active_links.txt
active_links.json

# Files used by scripts to autogenerate settings
FormatFactorySettingsDeclaration.h
Settings.cpp
32 changes: 24 additions & 8 deletions copyClickhouseRepoDocs.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#! ./bin/bash
echo "Start Cloning"

SCRIPT_NAME=$(basename "$0")

echo "[$SCRIPT_NAME] Start tasks for copying docs from ClickHouse repo"

# Clone ClickHouse repo
echo "[$SCRIPT_NAME] Start cloning ClickHouse repo"
git clone --depth 1 https://github.com/ClickHouse/ClickHouse.git
echo "Cloning completed"
echo "Start Copying"
echo "[$SCRIPT_NAME] Cloning completed"

# Copy docs folders from ClickHouse repo to docs folder
echo "[$SCRIPT_NAME] Start copying docs"
cp -r ClickHouse/docs/en/development docs/en/
cp -r ClickHouse/docs/en/engines docs/en/
cp -r ClickHouse/docs/en/getting-started docs/en/
Expand All @@ -11,14 +19,22 @@ cp -r ClickHouse/docs/en/operations docs/en/
cp -r ClickHouse/docs/en/sql-reference docs/en/
cp -r ClickHouse/docs/ru docs/
cp -r ClickHouse/docs/zh docs/
echo "Copying completed"

echo "----Generate Changelog----"
# Necessary for autogenerating settings
cp ClickHouse/src/Core/FormatFactorySettingsDeclaration.h "$(dirname "$0")"
cp ClickHouse/src/Core/Settings.cpp "$(dirname "$0")"

echo "[$SCRIPT_NAME] Copying completed"

echo "[$SCRIPT_NAME] Generate changelog"
cp docs/en/_placeholders/changelog/_index.md docs/en/whats-new/changelog/index.md
sed "0,/^# $(date +%Y) Changelog/d" \
< ClickHouse/CHANGELOG.md \
>> docs/en/whats-new/changelog/index.md
echo "Start Deleting ClickHouse"

# Delete ClickHouse repo
echo "[$SCRIPT_NAME] Start deleting ClickHouse repo"
rm -r ClickHouse
echo "Deleting ClickHouse folder completed"
echo "----END----"
echo "[$SCRIPT_NAME] Deleting ClickHouse repo completed"

echo "[$SCRIPT_NAME] Finish tasks for copying docs from ClickHouse repo"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"serve": "docusaurus serve",
"build-api-doc": "node clickhouseapi.js",
"build-swagger": "npx @redocly/cli build-docs https://api.clickhouse.cloud/v1 --output build/en/cloud/manage/api/swagger.html",
"new-build": "bash ./copyClickhouseRepoDocs.sh && yarn build-api-doc && yarn build && yarn build-swagger",
"new-build": "bash ./copyClickhouseRepoDocs.sh && bash ./scripts/settings/autogenerate-settings.sh && yarn build-api-doc && yarn build && yarn build-swagger",
"start": "docusaurus start",
"swizzle": "docusaurus swizzle",
"write-heading-ids": "docusaurus write-heading-ids"
Expand Down
77 changes: 77 additions & 0 deletions scripts/settings/autogenerate-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! ./bin/bash

SCRIPT_NAME=$(basename "$0")

echo "[$SCRIPT_NAME] Autogenerating settings"

# Install ClickHouse
if [ ! -f ./clickhouse ]; then
echo -e "[$SCRIPT_NAME] Installing ClickHouse binary\n"
curl https://clickhouse.com/ | sh
fi

# Autogenerate Format settings
./clickhouse -q "
WITH
'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
),
'---
title: Format Settings
sidebar_label: Format Settings
slug: /en/operations/settings/formats
toc_max_heading_level: 2
---
<!-- Autogenerated -->
These settings are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/FormatFactorySettings.h).
' AS prefix
SELECT prefix || (SELECT groupConcat(*) FROM main_content)
INTO OUTFILE 'docs/en/operations/settings/settings-formats.md' TRUNCATE FORMAT LineAsString
"

# Autogenerate Format settings
./clickhouse -q "
WITH
'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
),
'---
title: Core Settings
sidebar_label: Core Settings
slug: /en/operations/settings/settings
toc_max_heading_level: 2
---
<!-- Autogenerated -->
All below settings are also available in table [system.settings](/docs/en/operations/system-tables/settings). These settings are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).
' AS prefix
SELECT prefix || (SELECT groupConcat(*) FROM main_content)
INTO OUTFILE 'docs/en/operations/settings/settings.md' TRUNCATE FORMAT LineAsString
"

# Delete ClickHouse
if [ -f ./clickhouse ]; then
echo -e "\n[$SCRIPT_NAME] Deleting ClickHouse binary"
rm ./clickhouse
fi

echo "[$SCRIPT_NAME] Autogenerating settings completed"

0 comments on commit bd97095

Please sign in to comment.