2014-09-04 18:41:15 -04:00
|
|
|
#!/bin/bash -e
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2018-11-13 12:38:37 -05:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2014-09-04 20:01:49 -04:00
|
|
|
opt_api=1
|
2014-09-05 14:44:34 -04:00
|
|
|
opt_docs=1
|
2014-09-04 20:01:49 -04:00
|
|
|
while getopts ":adn" opt; do
|
|
|
|
case $opt in
|
|
|
|
n)
|
|
|
|
opt_dryrun="1"
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
opt_api=
|
|
|
|
;;
|
|
|
|
a)
|
|
|
|
opt_docs=
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2016-05-31 18:34:58 -04:00
|
|
|
# Set $version to Druid version (tag will be "druid-$version")
|
2014-08-01 18:12:00 -04:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
version="latest"
|
2013-09-27 21:50:02 -04:00
|
|
|
else
|
2014-08-01 18:12:00 -04:00
|
|
|
version=$1
|
2013-09-27 21:50:02 -04:00
|
|
|
fi
|
|
|
|
|
2016-05-31 18:34:58 -04:00
|
|
|
# Set $origin to name of origin remote
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
origin="origin"
|
|
|
|
else
|
|
|
|
origin=$2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use s3cmd if available, otherwise try awscli
|
|
|
|
if command -v s3cmd >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
s3sync="s3cmd sync --delete-removed"
|
|
|
|
else
|
|
|
|
s3sync="aws s3 sync --delete"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Location of git repository containing this script
|
2014-09-04 18:41:15 -04:00
|
|
|
druid=$(git -C "$(dirname "$0")" rev-parse --show-toplevel)
|
2014-08-01 18:42:22 -04:00
|
|
|
|
2014-09-04 18:41:15 -04:00
|
|
|
if [ -n "$(git -C "$druid" status --porcelain --untracked-files=no)" ]; then
|
|
|
|
echo "Working directory is not clean, aborting"
|
2014-08-01 18:42:22 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-09-04 18:41:15 -04:00
|
|
|
branch=druid-$version
|
|
|
|
if [ "$version" == "latest" ]; then
|
|
|
|
branch=master
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$(git tag -l "$branch")" ] && [ "$branch" != "master" ]; then
|
2014-08-01 18:12:00 -04:00
|
|
|
echo "Version tag does not exist: druid-$version"
|
2013-11-05 18:20:55 -05:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2014-08-01 18:12:00 -04:00
|
|
|
tmp=$(mktemp -d -t druid-docs-deploy)
|
2014-09-04 18:41:15 -04:00
|
|
|
target=$tmp/docs
|
|
|
|
src=$tmp/druid
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2014-08-01 18:12:00 -04:00
|
|
|
echo "Using Version [$version]"
|
|
|
|
echo "Working directory [$tmp]"
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2018-08-30 12:56:26 -04:00
|
|
|
git clone -q --depth 1 git@github.com:apache/incubator-druid-io.github.io.git "$target"
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2016-05-31 18:34:58 -04:00
|
|
|
remote=$(git -C "$druid" config --local --get "remote.$origin.url")
|
2014-09-04 18:41:15 -04:00
|
|
|
git clone -q --depth 1 --branch $branch $remote "$src"
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2014-09-04 20:01:49 -04:00
|
|
|
if [ -n "$opt_docs" ] ; then
|
2016-05-31 19:36:10 -04:00
|
|
|
# Copy docs
|
2014-09-04 20:01:49 -04:00
|
|
|
mkdir -p $target/docs/$version
|
|
|
|
rsync -a --delete "$src/docs/content/" $target/docs/$version
|
2016-05-31 18:34:58 -04:00
|
|
|
|
|
|
|
# Replace #{DRUIDVERSION} with current Druid version
|
|
|
|
# Escaping of $version is weak here, but it should be fine for typical version strings
|
2016-05-31 19:36:10 -04:00
|
|
|
find "$target/docs/$version" -name "*.md" -print0 | xargs -0 perl -pi -e's/\#\{DRUIDVERSION\}/'"$version"'/g'
|
2016-05-31 18:34:58 -04:00
|
|
|
|
|
|
|
# Create redirects
|
2016-05-31 19:36:10 -04:00
|
|
|
"$src/docs/_bin/make-redirects.py" "$target/docs/$version" "$src/docs/_redirects.json"
|
2014-09-04 20:01:49 -04:00
|
|
|
fi
|
2014-09-04 18:41:15 -04:00
|
|
|
|
|
|
|
# generate javadocs for releases (not for master)
|
2014-09-04 20:01:49 -04:00
|
|
|
if [ "$version" != "latest" ] && [ -n "$opt_api" ] ; then
|
2014-09-04 18:41:15 -04:00
|
|
|
(cd $src && mvn javadoc:aggregate)
|
|
|
|
mkdir -p $target/api/$version
|
2015-02-04 15:56:52 -05:00
|
|
|
if [ -z "$opt_dryrun" ]; then
|
2016-05-31 18:34:58 -04:00
|
|
|
$s3sync "$src/target/site/apidocs/" "s3://static.druid.io/api/$version/"
|
2015-02-04 15:56:52 -05:00
|
|
|
fi
|
2014-09-04 18:41:15 -04:00
|
|
|
fi
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2014-09-04 18:41:15 -04:00
|
|
|
updatebranch=update-docs-$version
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2014-09-04 18:41:15 -04:00
|
|
|
git -C $target checkout -b $updatebranch
|
|
|
|
git -C $target add -A .
|
|
|
|
git -C $target commit -m "Update $version docs"
|
2014-09-04 20:01:49 -04:00
|
|
|
if [ -z "$opt_dryrun" ]; then
|
|
|
|
git -C $target push origin $updatebranch
|
2013-09-27 21:50:02 -04:00
|
|
|
|
2014-09-04 20:01:49 -04:00
|
|
|
if [ -n "$GIT_TOKEN" ]; then
|
|
|
|
curl -u "$GIT_TOKEN:x-oauth-basic" -XPOST -d@- \
|
2018-08-30 12:56:26 -04:00
|
|
|
https://api.github.com/repos/apache/incubator-druid-io.github.io/pulls <<EOF
|
2014-08-01 18:12:00 -04:00
|
|
|
{
|
2015-02-04 15:56:52 -05:00
|
|
|
"title" : "Update Documentation for $version",
|
2014-09-04 18:41:15 -04:00
|
|
|
"head" : "$updatebranch",
|
2016-11-15 16:46:46 -05:00
|
|
|
"base" : "src"
|
2014-08-01 18:12:00 -04:00
|
|
|
}
|
|
|
|
EOF
|
2014-08-01 18:42:22 -04:00
|
|
|
|
2014-09-04 20:01:49 -04:00
|
|
|
else
|
|
|
|
echo "GitHub personal token not provided, not submitting pull request"
|
2018-08-30 12:56:26 -04:00
|
|
|
echo "Please go to https://github.com/apache/incubator-druid-io.github.io and submit a pull request from the \`$updatebranch\` branch"
|
2014-09-04 20:01:49 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf $tmp
|
2014-08-01 18:12:00 -04:00
|
|
|
else
|
2014-09-04 20:01:49 -04:00
|
|
|
echo "Not pushing. To see changes run:"
|
|
|
|
echo "git -C $target diff HEAD^1"
|
2014-08-01 18:12:00 -04:00
|
|
|
fi
|