diff --git a/.gitignore b/.gitignore index 968eb73bcd2..1c5436abe18 100644 --- a/.gitignore +++ b/.gitignore @@ -37,9 +37,7 @@ active_links.txt active_links.json # Files used by scripts to autogenerate settings and do spellcheck -FormatFactorySettingsDeclaration.h -FormatFactorySettings.h -Settings.cpp +scripts/settings/tmp # Files whose content gets autogenerated docs/en/cloud/manage/api/invitations-api-reference.md diff --git a/README.md b/README.md index 64c52dc6000..e8304788dc0 100644 --- a/README.md +++ b/README.md @@ -69,28 +69,22 @@ You can run a copy of this website locally within a few steps. Some folks find t # ✨ Done in 6.44s. ``` -1. Use Yarn to grab the latest documentation changes from the `clickhouse/clickhouse` repository: +1. Use Yarn to grab the latest documentation changes from the `ClickHouse/ClickHouse` repository: ```shell - yarn prep-from-master + yarn copy-clickhouse-repo-docs - # yarn run v1.22.19 - # Cloning into '/tmp/ch_temp_14714'... + # Cloning into 'ClickHouse'... # ... - # Prep completed - # ✨ Done in 16.44s + # Copying docs from ClickHouse ... + # Successfully executed copy from master + # ✨ Done in 18.56s. ``` - Alternatively, you can use a local copy of the `clickhouse/clickhouse` if you already have that repository cloned locally. + Alternatively, you can use a local copy of `ClickHouse/ClickHouse` if you already have that repository cloned locally with `-l`. ```shell - yarn prep-from-local "/Users/johnny/clickhouse/" - - # yarn run v1.22.19 - # $ bash -c 'array_root=($npm ... - # ... - # Prep completed - ✨ Done in 0.47s. + yarn copy-clickhouse-repo-docs -l "/Users/johnny/clickhouse/" ``` 1. Start the local web-server: diff --git a/copyClickhouseRepoDocs.sh b/copyClickhouseRepoDocs.sh deleted file mode 100755 index b403605921f..00000000000 --- a/copyClickhouseRepoDocs.sh +++ /dev/null @@ -1,54 +0,0 @@ -#! /bin/bash - -SCRIPT_NAME=$(basename "$0") - -rm -rf ClickHouse -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 temp -cp -r temp/ ClickHouse/ -rm -rf temp -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/ -cp -r ClickHouse/docs/en/interfaces docs/en/ -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/ - -# Necessary for autogenerating settings -cp ClickHouse/src/Core/FormatFactorySettings.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 -if grep -q "^# $(date +%Y) Changelog" ClickHouse/CHANGELOG.md; then - echo "Generating $(date +%Y) Changelog..." - sed "/^# $(date +%Y) Changelog/d" ClickHouse/CHANGELOG.md > temp.txt - echo "Changelog copied to temp.txt" - cat temp.txt >> docs/en/whats-new/changelog/index.md - echo "Changelog written to docs/en/whats-new/changelog/index.md" - rm -f temp.txt - echo "$(date +%Y) Changelog was updated." -else - current_year="$(date +%Y)" - previous_year="$(($current_year - 1))" - echo "No Changelog found for $current_year." - echo -e ":::note\nThere have been no new releases yet for $current_year. \n View changelog for the year [$previous_year](/docs/en/whats-new/changelog/$previous_year).\n:::" >> docs/en/whats-new/changelog/index.md -fi - -# Delete ClickHouse repo -echo "[$SCRIPT_NAME] Start deleting ClickHouse repo" -rm -rf ClickHouse -echo "[$SCRIPT_NAME] Deleting ClickHouse repo completed" - -echo "[$SCRIPT_NAME] Finish tasks for copying docs from ClickHouse repo" diff --git a/docusaurus.config.js b/docusaurus.config.js index f9fe6c79b13..06b32382d90 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -318,7 +318,7 @@ const config = { async postBuild({ siteConfig = {}, routesPaths = [], outDir }) { // Print out to console all the rendered routes. routesPaths.map((route) => { - console.log(route) + //console.log(route) }) }, } diff --git a/package.json b/package.json index 59b21a2bc98..4e5f80031dc 100644 --- a/package.json +++ b/package.json @@ -4,22 +4,22 @@ "private": true, "config": { "prep_array_en": "docs/en/development docs/en/engines docs/en/getting-started docs/en/interfaces docs/en/operations docs/en/sql-reference", - "prep_array_root": "docs/ru docs/zh" + "prep_array_root": "docs/ru docs/zh", + "autogen_needed_files": "src/Core/FormatFactorySettings.h src/Core/Settings.cpp CHANGELOG.md" }, "scripts": { - "build": "docusaurus build", + "build": "yarn copy-clickhouse-repo-docs && yarn generate-changelog && yarn autogenerate-settings && yarn build-api-doc && yarn build-swagger && docusaurus build", "clear": "docusaurus clear && bash ./placeholderReset.sh", "deploy": "docusaurus deploy", "docusaurus": "docusaurus", - "prep-from-local": "bash scripts/prep-from-local.sh", - "prep-from-master": "bash scripts/prep-from-master.sh", - "copy-clickhouse-repo-docs": "bash ./copyClickhouseRepoDocs.sh", + "copy-clickhouse-repo-docs": "bash scripts/copy-clickhouse-repo-docs.sh", "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", - "auto-generate-settings": "bash ./scripts/settings/autogenerate-settings.sh", - "auto-generate-table-of-contents": "bash ./scripts/autogenerate-table-of-contents.sh", - "new-build": "yarn copy-clickhouse-repo-docs && yarn auto-generate-settings && yarn auto-generate-table-of-contents && yarn build-api-doc && yarn build && yarn build-swagger", + "build-swagger": "npx @redocly/cli build-docs https://api.clickhouse.cloud/v1 --output build/en/cloud/manage/api/swagger.html", + "prep-from-local": "bash ./scripts/copy-clickhouse-repo-docs.sh -l $1", + "autogenerate-settings": "bash ./scripts/settings/autogenerate-settings.sh", + "generate-changelog": "bash ./scripts/generate-changelog.sh", + "new-build": "yarn copy-clickhouse-repo-docs && yarn generate-changelog && yarn autogenerate-settings && yarn build-api-doc && yarn build-swagger && docusaurus build", "start": "docusaurus start", "swizzle": "docusaurus swizzle", "write-heading-ids": "docusaurus write-heading-ids", @@ -32,7 +32,6 @@ "@docusaurus/theme-mermaid": "3.7.0", "@docusaurus/theme-search-algolia": "^3.7.0", "@mdx-js/react": "^3.1.0", - "@yaireo/tagify": "^4.33.2", "@radix-ui/react-navigation-menu": "^1.2.4", "axios": "^1.7.9", "clsx": "^2.1.0", @@ -62,6 +61,7 @@ "@playwright/test": "^1.49.1", "@types/react": "^19.0.4", "cheerio": "^1.0.0", + "rsync": "^0.6.1", "typescript": "^5.7.3" }, "browserslist": { diff --git a/scripts/copy-clickhouse-repo-docs.sh b/scripts/copy-clickhouse-repo-docs.sh new file mode 100755 index 00000000000..de5416ae52c --- /dev/null +++ b/scripts/copy-clickhouse-repo-docs.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +function parse_args() { + + while getopts "hl:" opt; do + case "$opt" in + h) + # Display the usage information and exit when -h is provided + echo "Usage: $0 [-l path_to_local_clickhouse_repo]" + echo "" + echo "Options:" + echo " -l Path to a local copy of the ClickHouse repository." + echo " -h Display this help message." + exit 0 + ;; + l) + local_path="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac + done + + echo "$local_path" +} + +# Validate local path exists and ends in ClickHouse +function validate_local() { + + if [[ -d "$local_path" && "$local_path" == *"ClickHouse" ]]; then + return 0 + else + echo "Please provide a valid path to your local ClickHouse repository." + exit 1 + fi +} + +# Copy files/folders using rsync (or fallback to cp) +copy_item() { + local source="$1" + local destination="$2" + + if $has_rsync; then + rsync -a "$source" "$destination" + else + cp -r "$source" "$destination" + if [ $? -ne 0 ]; then + echo "Error copying $source to $destination" + error=1 + fi + fi +} + +# Define function to copy docs locally +function copy_docs_locally() { + local local_path=$1 + + # Validate local path only if it's provided + if [[ -n "$local_path" ]]; then + validate_local "$local_path" + fi + + # Read package.json to get list of docs folders and files + package_json=$(cat "$(pwd)/package.json") + + # Extract docs_folders_en + docs_folders_en=$(echo "$package_json" | awk -F'"' '/"prep_array_en":/{print $4}') + + # Extract docs_folders_other + docs_folders_other=$(echo "$package_json" | awk -F'"' '/"prep_array_root":/{print $4}') + + # Extract files_for_autogen_settings + files_for_autogen_settings=$(echo "$package_json" | awk -F'"' '/"autogen_needed_files":/{print $4}') + + if [ "$docs_folders_en" = "" ] || [ "$docs_folders_other" = "" ] || [ "$files_for_autogen_settings" = "" ] + then + echo "An error occurred trying to extract directory and file names from package.json" + exit 1 + fi + + error=0 + # Copy docs folders + for folder in $docs_folders_en; do + copy_item "$local_path/$folder" "docs/en" + done + + for folder in $docs_folders_other; do + copy_item "$local_path/$folder" "docs/" + done + + # check if tmp directory exists, if not make it + if [[ -d "scripts/tmp" ]]; then + echo "scripts/tmp already exists" + else + mkdir scripts/tmp + fi + # Copy files for autogen settings + for source_file in $files_for_autogen_settings; do + copy_item "$local_path/$source_file" "scripts/tmp" + done + + if [ "$error" -eq 1 ]; then + echo "an error occurred copying the files" + exit 1 + fi +} + +main() { + parse_args "$@" + + # Check if rsync is available + has_rsync=false + if command -v rsync &> /dev/null; then + echo "rsync found" + has_rsync=true + else + echo "rsync not found - falling back to use cp command. For faster dev builds we recommend installing rsync." + fi + + # If no local path is provided, clone the ClickHouse repo + + if [[ -z "$local_path" ]]; then + + git clone --depth 1 --branch master https://github.com/ClickHouse/ClickHouse + + # Copy docs from cloned repository + copy_docs_locally "$(pwd)/ClickHouse" + + # Remove cloned repository + rm -rf ClickHouse + + echo "Successfully executed copy from master" + else + # Copy docs from the provided local path + validate_local "$local_path" + copy_docs_locally "$local_path" + echo "Successfully executed local copy" + fi +} + +main "$@" diff --git a/scripts/generate-changelog.sh b/scripts/generate-changelog.sh new file mode 100755 index 00000000000..4bef6d7a70f --- /dev/null +++ b/scripts/generate-changelog.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +script_dir=$(dirname "$0") # Get the directory of the script +parent_dir=$(realpath "$script_dir") # Get the parent directory + +echo "Running Changelog Generation Script" +cp "$parent_dir/../docs/en/_placeholders/changelog/_index.md" "$parent_dir/../docs/en/whats-new/changelog/index.md" +if grep -q "^# $(date +%Y) Changelog" "$parent_dir/tmp/CHANGELOG.md"; then + echo "Generating $(date +%Y) Changelog..." + sed "/^# $(date +%Y) Changelog/d" "$parent_dir/tmp/CHANGELOG.md" > temp.txt + echo "Changelog copied to temp.txt" + cat temp.txt >> "$parent_dir/../docs/en/whats-new/changelog/index.md" + echo "Changelog written to docs/en/whats-new/changelog/index.md" + rm -f temp.txt + echo "$(date +%Y) Changelog was updated." +else + current_year="$(date +%Y)" + previous_year="$(($current_year - 1))" + echo "No Changelog found for $current_year." + echo -e ":::note\nThere have been no new releases yet for $current_year. \n View changelog for the year [$previous_year](/docs/en/whats-new/changelog/$previous_year).\n:::" >> "$parent_dir/../docs/en/whats-new/changelog/index.md" +fi diff --git a/scripts/prep-from-local.sh b/scripts/prep-from-local.sh deleted file mode 100644 index d9bc81e34df..00000000000 --- a/scripts/prep-from-local.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! ./bin/bash - -# Due to the fact that some of the documentation content is stored on the main repo at ClickHouse/ClickHouse -# this script is used to copy across those documents to ClickHouse/clickhouse-docs from a local copy of the -# repo. To use it provide the path to ClickHouse/ClickHouse locally as a command line argument. -# eg: yarn prep-from-local "home/users/Desktop/ClickHouse" - -array_root=($npm_package_config_prep_array_root) -array_en=($npm_package_config_prep_array_en) -error_flag=0 - -# Check if any arguments were provided -if [ $# -eq 0 ]; then - echo -e "\033[0;31mError: No path for ClickHouse provided as command-line argument. \033[0m \neg: yarn prep-from-local \"/home/user/Desktop/ClickHouse\"" - exit 1 -fi - -# Copy across english language docs folders from main repo -for folder in ${array_en[@]} -do - if ! cp -r $1/$folder docs/en; then - echo -e "\033[0;31mFailed to copy $folder from [$0]\033[0m" - error_flag=1 - else - echo -e "\033[0;32mCopied $folder from [$0]\033[0m" - fi -done - -# Copy across remaining language docs folders from main repo -for folder in ${array_root[@]} -do - if ! cp -r $1/$folder docs/; then - echo -e "\033[0;31mFailed to copy $folder from [$0]\033[0m" - error_flag=1 - else - echo -e "\033[0;32mCopied $folder from [$0]\033[0m" - fi -done - -if [ $error_flag -eq 1 ]; then - exit 1 -fi - -echo -e "\033[0;32mPreparation from local completed successfully\033[0m" diff --git a/scripts/prep-from-master.sh b/scripts/prep-from-master.sh deleted file mode 100644 index 71e264155d6..00000000000 --- a/scripts/prep-from-master.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! ./bin/bash - -# Due to the fact that some of the documentation content is stored on the main repo at ClickHouse/ClickHouse -# this script is used to copy across those documents to ClickHouse/clickhouse-docs from remote repository. - -array_root=($npm_package_config_prep_array_root) -array_en=($npm_package_config_prep_array_en) -ch_temp=/tmp/ch_temp_$RANDOM && mkdir -p $ch_temp && git clone --depth 1 --branch master https://github.com/ClickHouse/ClickHouse $ch_temp - -bash scripts/prep-from-local.sh "$ch_temp" -rm -rf $ch_temp diff --git a/scripts/settings/autogenerate-settings.sh b/scripts/settings/autogenerate-settings.sh index 2cf8870ece5..0db85ab0606 100755 --- a/scripts/settings/autogenerate-settings.sh +++ b/scripts/settings/autogenerate-settings.sh @@ -1,16 +1,54 @@ -#! /bin/bash +#!/usr/bin/env bash +if ! command -v bash &> /dev/null; then + echo "Error: bash not found!" + exit 1 +fi + +# always run "yarn copy-clickhouse-repo-docs" before invoking this script +# otherwise it will fail not being able to find the files it needs which +# are copied to scripts/tmp and configured in package.json -> "autogen_settings_needed_files" + +set -x + +if command -v curl >/dev/null 2>&1; then + echo "curl is installed" +else + echo "curl is NOT installed" + exit 1 +fi + + +target_dir=$(dirname "$(dirname "$(realpath "$0")")") SCRIPT_NAME=$(basename "$0") +tmp_dir="$target_dir/tmp" -echo "[$SCRIPT_NAME] Autogenerating settings" +mkdir -p "$tmp_dir" || exit 1 +cd "$tmp_dir" || exit 1 + +script_url="https://clickhouse.com/" # URL of the installation script +script_filename="clickhouse" # Choose a descriptive name +script_path="$tmp_dir/$script_filename" # Install ClickHouse -if [ ! -f ./clickhouse ]; then +if [ ! -f "$script_path" ]; then echo -e "[$SCRIPT_NAME] Installing ClickHouse binary\n" curl https://clickhouse.com/ | sh fi +if [[ ! -f "$script_path" ]]; then + echo "Error: File not found after curl download!" + exit 1 +fi + +echo "Downloaded to: $script_path" +echo "[$SCRIPT_NAME] Auto-generating settings" + # Autogenerate Format settings +chmod +x "$script_path" || { echo "Error: Failed to set execute permission"; exit 1; } + +root=$(dirname "$(dirname "$(realpath "$tmp_dir")")") + ./clickhouse -q " WITH 'FormatFactorySettings.h' AS cpp_file, @@ -39,10 +77,11 @@ import BetaBadge from \'@theme/badges/BetaBadge\'; 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 -" +INTO OUTFILE 'settings-formats.md' TRUNCATE FORMAT LineAsString +" || { echo "Failed to Autogenerate Format settings"; exit 1; } # Autogenerate settings ./clickhouse -q " @@ -73,16 +112,21 @@ import BetaBadge from \'@theme/badges/BetaBadge\'; 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 -" +INTO OUTFILE 'settings.md' TRUNCATE FORMAT LineAsString +" || { echo "Failed to Autogenerate Core settings"; exit 1; } -# Delete ClickHouse -if [ -f ./clickhouse ]; then - echo -e "\n[$SCRIPT_NAME] Deleting ClickHouse binary" - rm ./clickhouse -fi +mv settings-formats.md "$root/docs/en/operations/settings" || { echo "Failed to move generated settings-format.md"; exit 1; } +mv settings.md "$root/docs/en/operations/settings" || { echo "Failed to move generated settings.md"; exit 1; } + +echo "[$SCRIPT_NAME] Auto-generation of settings markdown pages completed successfully" +# perform cleanup +rm -rf "$tmp_dir"/settings-formats.md +rm -rf "$tmp_dir"/settings.md +rm -rf "$tmp_dir"/FormatFactorySettings.h +rm -rf "$tmp_dir"/Settings.cpp echo "[$SCRIPT_NAME] Autogenerating settings completed" diff --git a/yarn.lock b/yarn.lock index 35e27a69067..409df9bd4ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5925,6 +5925,11 @@ flat@^5.0.2: resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== +flexsearch@^0.7.43: + version "0.7.43" + resolved "https://registry.yarnpkg.com/flexsearch/-/flexsearch-0.7.43.tgz#34f89b36278a466ce379c5bf6fb341965ed3f16c" + integrity sha512-c5o/+Um8aqCSOXGcZoqZOm+NqtVwNsvVpWv6lfmSclU954O3wvQKxxK8zj74fPaSJbXpSLTs4PRhh+wnoCXnKg== + follow-redirects@^1.0.0, follow-redirects@^1.15.6: version "1.15.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" @@ -9955,6 +9960,11 @@ roughjs@^4.6.6: points-on-curve "^0.2.0" points-on-path "^0.2.1" +rsync@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/rsync/-/rsync-0.6.1.tgz#3681a0098bd8750448f8bf9da1fee09f7763742b" + integrity sha512-39HcwWuM67CQ9tHloazShXWUOWa2m3SGqX6XQhQMSj0VCQMkSI9PodoxM7/+hKf2p4v2umbhfoarYqd1gwII/w== + rtlcss@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/rtlcss/-/rtlcss-4.3.0.tgz#f8efd4d5b64f640ec4af8fa25b65bacd9e07cc97"