2017-04-10 14:24:53 +00:00
#!/usr/bin/env bash
set -ex
2020-01-21 14:36:12 +00:00
2017-04-10 14:24:53 +00:00
BASE_DIR = $( dirname $( readlink -f $0 ) )
2019-03-26 09:50:28 +00:00
BUILD_DIR = " ${ BASE_DIR } /../build "
2020-01-28 18:51:44 +00:00
PUBLISH_DIR = " ${ BASE_DIR } /../publish "
2020-04-09 18:56:03 +00:00
BASE_DOMAIN = " ${ BASE_DOMAIN :- content .clickhouse.tech } "
2020-04-09 20:32:35 +00:00
GIT_TEST_URI = " ${ GIT_TEST_URI :- git @github.com : ClickHouse /clickhouse-website-content.git } "
2020-04-09 18:56:03 +00:00
GIT_PROD_URI = "git@github.com:ClickHouse/clickhouse-website-content.git"
2020-12-21 20:04:22 +00:00
EXTRA_BUILD_ARGS = " ${ EXTRA_BUILD_ARGS :- --minify --verbose } "
2020-01-29 14:56:52 +00:00
2017-04-10 14:24:53 +00:00
if [ [ -z " $1 " ] ]
then
2019-03-26 09:50:28 +00:00
source " ${ BASE_DIR } /venv/bin/activate "
2020-03-21 04:56:32 +00:00
python3 " ${ BASE_DIR } /build.py " ${ EXTRA_BUILD_ARGS }
2020-12-21 18:26:31 +00:00
rm -rf " ${ PUBLISH_DIR } "
mkdir " ${ PUBLISH_DIR } " && cd " ${ PUBLISH_DIR } "
2020-12-21 05:59:40 +00:00
# Will make a repository with website content as the only commit.
git init
2020-12-21 06:02:06 +00:00
git remote add origin " ${ GIT_TEST_URI } "
2020-01-29 13:36:13 +00:00
git config user.email "robot-clickhouse@yandex-team.ru"
git config user.name "robot-clickhouse"
2020-12-21 05:59:40 +00:00
# Add files.
2020-01-28 18:51:44 +00:00
cp -R " ${ BUILD_DIR } " /* .
2020-03-15 10:53:00 +00:00
echo -n " ${ BASE_DOMAIN } " > CNAME
2020-01-28 19:47:58 +00:00
echo -n "" > README.md
2020-02-03 10:00:49 +00:00
echo -n "" > ".nojekyll"
2020-01-28 19:31:35 +00:00
cp " ${ BASE_DIR } /../../LICENSE " .
2020-01-28 18:51:44 +00:00
git add *
2020-02-03 10:00:49 +00:00
git add ".nojekyll"
2020-12-21 05:59:40 +00:00
2020-12-23 03:32:55 +00:00
git commit --quiet -m " Add new release at $( date) "
2021-01-01 15:49:09 +00:00
# Push to GitHub rewriting the existing contents.
# Sometimes it does not work with error message "! [remote rejected] master -> master (cannot lock ref 'refs/heads/master': is at 42a0f6b6b6c7be56a469441b4bf29685c1cebac3 but expected 520e9b02c0d4678a2a5f41d2f561e6532fb98cc1)"
for _ in { 1..10} ; do git push --force origin master && break; sleep 5; done
2020-12-21 05:59:40 +00:00
2020-03-13 19:35:03 +00:00
if [ [ ! -z " ${ CLOUDFLARE_TOKEN } " ] ]
then
sleep 1m
2020-12-23 10:57:07 +00:00
# https://api.cloudflare.com/#zone-purge-files-by-cache-tags,-host-or-prefix
2020-12-23 14:19:51 +00:00
POST_DATA = '{"hosts":["content.clickhouse.tech"]}'
2020-12-23 10:57:07 +00:00
curl -X POST "https://api.cloudflare.com/client/v4/zones/4fc6fb1d46e87851605aa7fa69ca6fe0/purge_cache" -H " Authorization: Bearer ${ CLOUDFLARE_TOKEN } " -H "Content-Type:application/json" --data " ${ POST_DATA } "
2020-03-13 19:35:03 +00:00
fi
2017-04-10 14:24:53 +00:00
fi