Skip to content

Commit bb038ac

Browse files
authored
Merge pull request #3168 from Blargian/separate-out-new-build
Improve build-scripts
2 parents 0bd09fd + 881c7a8 commit bb038ac

File tree

11 files changed

+250
-149
lines changed

11 files changed

+250
-149
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ active_links.txt
3737
active_links.json
3838

3939
# Files used by scripts to autogenerate settings and do spellcheck
40-
FormatFactorySettingsDeclaration.h
41-
FormatFactorySettings.h
42-
Settings.cpp
40+
scripts/settings/tmp
4341

4442
# Files whose content gets autogenerated
4543
docs/en/cloud/manage/api/invitations-api-reference.md

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,22 @@ You can run a copy of this website locally within a few steps. Some folks find t
6969
# ✨ Done in 6.44s.
7070
```
7171

72-
1. Use Yarn to grab the latest documentation changes from the `clickhouse/clickhouse` repository:
72+
1. Use Yarn to grab the latest documentation changes from the `ClickHouse/ClickHouse` repository:
7373

7474
```shell
75-
yarn prep-from-master
75+
yarn copy-clickhouse-repo-docs
7676
77-
# yarn run v1.22.19
78-
# Cloning into '/tmp/ch_temp_14714'...
77+
# Cloning into 'ClickHouse'...
7978
# ...
80-
# Prep completed
81-
# ✨ Done in 16.44s
79+
# Copying docs from ClickHouse ...
80+
# Successfully executed copy from master
81+
# ✨ Done in 18.56s.
8282
```
8383

84-
Alternatively, you can use a local copy of the `clickhouse/clickhouse` if you already have that repository cloned locally.
84+
Alternatively, you can use a local copy of `ClickHouse/ClickHouse` if you already have that repository cloned locally with `-l`.
8585

8686
```shell
87-
yarn prep-from-local "/Users/johnny/clickhouse/"
88-
89-
# yarn run v1.22.19
90-
# $ bash -c 'array_root=($npm ...
91-
# ...
92-
# Prep completed
93-
✨ Done in 0.47s.
87+
yarn copy-clickhouse-repo-docs -l "/Users/johnny/clickhouse/"
9488
```
9589

9690
1. Start the local web-server:

copyClickhouseRepoDocs.sh

Lines changed: 0 additions & 54 deletions
This file was deleted.

docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const config = {
318318
async postBuild({ siteConfig = {}, routesPaths = [], outDir }) {
319319
// Print out to console all the rendered routes.
320320
routesPaths.map((route) => {
321-
console.log(route)
321+
//console.log(route)
322322
})
323323
},
324324
}

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
"private": true,
55
"config": {
66
"prep_array_en": "docs/en/development docs/en/engines docs/en/getting-started docs/en/interfaces docs/en/operations docs/en/sql-reference",
7-
"prep_array_root": "docs/ru docs/zh"
7+
"prep_array_root": "docs/ru docs/zh",
8+
"autogen_needed_files": "src/Core/FormatFactorySettings.h src/Core/Settings.cpp CHANGELOG.md"
89
},
910
"scripts": {
10-
"build": "docusaurus build",
11+
"build": "yarn copy-clickhouse-repo-docs && yarn generate-changelog && yarn autogenerate-settings && yarn build-api-doc && yarn build-swagger && docusaurus build",
1112
"clear": "docusaurus clear && bash ./placeholderReset.sh",
1213
"deploy": "docusaurus deploy",
1314
"docusaurus": "docusaurus",
14-
"prep-from-local": "bash scripts/prep-from-local.sh",
15-
"prep-from-master": "bash scripts/prep-from-master.sh",
16-
"copy-clickhouse-repo-docs": "bash ./copyClickhouseRepoDocs.sh",
15+
"copy-clickhouse-repo-docs": "bash scripts/copy-clickhouse-repo-docs.sh",
1716
"serve": "docusaurus serve",
1817
"build-api-doc": "node clickhouseapi.js",
19-
"build-swagger": "npx @redocly/cli build-docs https://api.clickhouse.cloud/v1 --output build/en/cloud/manage/api/swagger.html",
20-
"auto-generate-settings": "bash ./scripts/settings/autogenerate-settings.sh",
21-
"auto-generate-table-of-contents": "bash ./scripts/autogenerate-table-of-contents.sh",
22-
"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",
18+
"build-swagger": "npx @redocly/cli build-docs https://api.clickhouse.cloud/v1 --output build/en/cloud/manage/api/swagger.html",
19+
"prep-from-local": "bash ./scripts/copy-clickhouse-repo-docs.sh -l $1",
20+
"autogenerate-settings": "bash ./scripts/settings/autogenerate-settings.sh",
21+
"generate-changelog": "bash ./scripts/generate-changelog.sh",
22+
"new-build": "yarn copy-clickhouse-repo-docs && yarn generate-changelog && yarn autogenerate-settings && yarn build-api-doc && yarn build-swagger && docusaurus build",
2323
"start": "docusaurus start",
2424
"swizzle": "docusaurus swizzle",
2525
"write-heading-ids": "docusaurus write-heading-ids",
@@ -32,7 +32,6 @@
3232
"@docusaurus/theme-mermaid": "3.7.0",
3333
"@docusaurus/theme-search-algolia": "^3.7.0",
3434
"@mdx-js/react": "^3.1.0",
35-
"@yaireo/tagify": "^4.33.2",
3635
"@radix-ui/react-navigation-menu": "^1.2.4",
3736
"axios": "^1.7.9",
3837
"clsx": "^2.1.0",
@@ -62,6 +61,7 @@
6261
"@playwright/test": "^1.49.1",
6362
"@types/react": "^19.0.4",
6463
"cheerio": "^1.0.0",
64+
"rsync": "^0.6.1",
6565
"typescript": "^5.7.3"
6666
},
6767
"browserslist": {
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
3+
function parse_args() {
4+
5+
while getopts "hl:" opt; do
6+
case "$opt" in
7+
h)
8+
# Display the usage information and exit when -h is provided
9+
echo "Usage: $0 [-l path_to_local_clickhouse_repo]"
10+
echo ""
11+
echo "Options:"
12+
echo " -l Path to a local copy of the ClickHouse repository."
13+
echo " -h Display this help message."
14+
exit 0
15+
;;
16+
l)
17+
local_path="$OPTARG"
18+
;;
19+
\?)
20+
echo "Invalid option: -$OPTARG" >&2
21+
exit 1
22+
;;
23+
esac
24+
done
25+
26+
echo "$local_path"
27+
}
28+
29+
# Validate local path exists and ends in ClickHouse
30+
function validate_local() {
31+
32+
if [[ -d "$local_path" && "$local_path" == *"ClickHouse" ]]; then
33+
return 0
34+
else
35+
echo "Please provide a valid path to your local ClickHouse repository."
36+
exit 1
37+
fi
38+
}
39+
40+
# Copy files/folders using rsync (or fallback to cp)
41+
copy_item() {
42+
local source="$1"
43+
local destination="$2"
44+
45+
if $has_rsync; then
46+
rsync -a "$source" "$destination"
47+
else
48+
cp -r "$source" "$destination"
49+
if [ $? -ne 0 ]; then
50+
echo "Error copying $source to $destination"
51+
error=1
52+
fi
53+
fi
54+
}
55+
56+
# Define function to copy docs locally
57+
function copy_docs_locally() {
58+
local local_path=$1
59+
60+
# Validate local path only if it's provided
61+
if [[ -n "$local_path" ]]; then
62+
validate_local "$local_path"
63+
fi
64+
65+
# Read package.json to get list of docs folders and files
66+
package_json=$(cat "$(pwd)/package.json")
67+
68+
# Extract docs_folders_en
69+
docs_folders_en=$(echo "$package_json" | awk -F'"' '/"prep_array_en":/{print $4}')
70+
71+
# Extract docs_folders_other
72+
docs_folders_other=$(echo "$package_json" | awk -F'"' '/"prep_array_root":/{print $4}')
73+
74+
# Extract files_for_autogen_settings
75+
files_for_autogen_settings=$(echo "$package_json" | awk -F'"' '/"autogen_needed_files":/{print $4}')
76+
77+
if [ "$docs_folders_en" = "" ] || [ "$docs_folders_other" = "" ] || [ "$files_for_autogen_settings" = "" ]
78+
then
79+
echo "An error occurred trying to extract directory and file names from package.json"
80+
exit 1
81+
fi
82+
83+
error=0
84+
# Copy docs folders
85+
for folder in $docs_folders_en; do
86+
copy_item "$local_path/$folder" "docs/en"
87+
done
88+
89+
for folder in $docs_folders_other; do
90+
copy_item "$local_path/$folder" "docs/"
91+
done
92+
93+
# check if tmp directory exists, if not make it
94+
if [[ -d "scripts/tmp" ]]; then
95+
echo "scripts/tmp already exists"
96+
else
97+
mkdir scripts/tmp
98+
fi
99+
# Copy files for autogen settings
100+
for source_file in $files_for_autogen_settings; do
101+
copy_item "$local_path/$source_file" "scripts/tmp"
102+
done
103+
104+
if [ "$error" -eq 1 ]; then
105+
echo "an error occurred copying the files"
106+
exit 1
107+
fi
108+
}
109+
110+
main() {
111+
parse_args "$@"
112+
113+
# Check if rsync is available
114+
has_rsync=false
115+
if command -v rsync &> /dev/null; then
116+
echo "rsync found"
117+
has_rsync=true
118+
else
119+
echo "rsync not found - falling back to use cp command. For faster dev builds we recommend installing rsync."
120+
fi
121+
122+
# If no local path is provided, clone the ClickHouse repo
123+
124+
if [[ -z "$local_path" ]]; then
125+
126+
git clone --depth 1 --branch master https://github.com/ClickHouse/ClickHouse
127+
128+
# Copy docs from cloned repository
129+
copy_docs_locally "$(pwd)/ClickHouse"
130+
131+
# Remove cloned repository
132+
rm -rf ClickHouse
133+
134+
echo "Successfully executed copy from master"
135+
else
136+
# Copy docs from the provided local path
137+
validate_local "$local_path"
138+
copy_docs_locally "$local_path"
139+
echo "Successfully executed local copy"
140+
fi
141+
}
142+
143+
main "$@"

scripts/generate-changelog.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
script_dir=$(dirname "$0") # Get the directory of the script
4+
parent_dir=$(realpath "$script_dir") # Get the parent directory
5+
6+
echo "Running Changelog Generation Script"
7+
cp "$parent_dir/../docs/en/_placeholders/changelog/_index.md" "$parent_dir/../docs/en/whats-new/changelog/index.md"
8+
if grep -q "^# $(date +%Y) Changelog" "$parent_dir/tmp/CHANGELOG.md"; then
9+
echo "Generating $(date +%Y) Changelog..."
10+
sed "/^# $(date +%Y) Changelog/d" "$parent_dir/tmp/CHANGELOG.md" > temp.txt
11+
echo "Changelog copied to temp.txt"
12+
cat temp.txt >> "$parent_dir/../docs/en/whats-new/changelog/index.md"
13+
echo "Changelog written to docs/en/whats-new/changelog/index.md"
14+
rm -f temp.txt
15+
echo "$(date +%Y) Changelog was updated."
16+
else
17+
current_year="$(date +%Y)"
18+
previous_year="$(($current_year - 1))"
19+
echo "No Changelog found for $current_year."
20+
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"
21+
fi

scripts/prep-from-local.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

scripts/prep-from-master.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)