mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
improve script for updating clickhouse-docs
This commit is contained in:
parent
bd496654bb
commit
4b0b5301be
22
docs/get-clickhouse-docs.sh
Normal file → Executable file
22
docs/get-clickhouse-docs.sh
Normal file → Executable file
@ -27,5 +27,27 @@ else
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
set_git_hook="$2"
|
||||
elif [ ! -n "$1" ]; then
|
||||
read -rp "Would you like to setup git hook for automatic update? (y|n): " set_git_hook
|
||||
fi
|
||||
|
||||
if [ "$set_git_hook" = "y" ]; then
|
||||
hook_command="$(pwd)/pull-clickhouse-docs-hook.sh 24"
|
||||
hook_file=$(realpath "$(pwd)/../.git/hooks/post-checkout")
|
||||
already_have=$(grep -Faq "pull-clickhouse-docs-hook.sh" "$hook_file" 2>/dev/null && echo 1 || echo 0)
|
||||
if [ $already_have -eq 0 ]; then
|
||||
echo "Appending '$hook_command' to $hook_file"
|
||||
echo "$hook_command" >> "$hook_file"
|
||||
chmod u+x "$hook_file" # Just in case it did not exist before append
|
||||
else
|
||||
echo "Looks like the update hook already exists, will not add another one"
|
||||
fi
|
||||
elif [ ! "$set_git_hook" = "n" ]; then
|
||||
echo "Expected 'y' or 'n', got '$set_git_hook', will not setup git hook"
|
||||
fi
|
||||
|
||||
git clone "$git_url" "clickhouse-docs"
|
||||
fi
|
||||
|
27
docs/pull-clickhouse-docs-hook.sh
Executable file
27
docs/pull-clickhouse-docs-hook.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
# The script to update user-guides documentation repo
|
||||
# https://github.com/ClickHouse/clickhouse-docs
|
||||
|
||||
WORKDIR=$(dirname "$0")
|
||||
WORKDIR=$(readlink -f "${WORKDIR}")
|
||||
cd "$WORKDIR"
|
||||
|
||||
UPDATE_PERIOD_HOURS="${1:-24}" # By default update once per 24 hours; 0 means "always update"
|
||||
|
||||
if [ ! -d "clickhouse-docs" ]; then
|
||||
echo "There's no clickhouse-docs/ dir, run get-clickhouse-docs.sh first to clone the repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Do not update it too often
|
||||
LAST_FETCH_TS=$(stat -c %Y clickhouse-docs/.git/FETCH_HEAD 2>/dev/null || echo 0)
|
||||
CURRENT_TS=$(date +%s)
|
||||
HOURS_SINCE_LAST_FETCH=$(( (CURRENT_TS - LAST_FETCH_TS) / 60 / 60 ))
|
||||
|
||||
if [ "$HOURS_SINCE_LAST_FETCH" -lt "$UPDATE_PERIOD_HOURS" ]; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo "Updating clickhouse-docs..."
|
||||
git -C clickhouse-docs pull
|
Loading…
Reference in New Issue
Block a user