2015-12-04 15:54:05 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-01-18 17:08:23 +01:00
|
|
|
# This script is executed by Travis CI when a PR is merged (i.e. in the `after_success` step).
|
2015-12-04 15:54:05 +01:00
|
|
|
set -ev
|
|
|
|
|
|
|
|
function initialize {
|
|
|
|
if [ -z "$TLDRHOME" ]; then
|
|
|
|
export TLDRHOME=${TRAVIS_BUILD_DIR:-`pwd`}
|
|
|
|
fi
|
|
|
|
export TLDR_ARCHIVE="tldr.zip"
|
|
|
|
export SITE_HOME="$HOME/site"
|
|
|
|
export SITE_URL="github.com/tldr-pages/tldr-pages.github.io"
|
|
|
|
|
|
|
|
git config --global user.email "travis@travis-ci.org"
|
|
|
|
git config --global user.name "Travis CI"
|
|
|
|
git config --global push.default simple
|
|
|
|
git config --global diff.zip.textconv "unzip -c -a"
|
|
|
|
}
|
|
|
|
|
|
|
|
function rebuild_index {
|
2016-01-19 20:44:37 +01:00
|
|
|
npm run build-index
|
2015-12-04 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_archive {
|
|
|
|
rm -f $TLDR_ARCHIVE
|
|
|
|
|
|
|
|
cd $TLDRHOME/
|
2018-11-09 10:57:04 +01:00
|
|
|
zip -r $TLDR_ARCHIVE pages*/ LICENSE.md
|
2015-12-04 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload_assets {
|
2018-01-18 17:08:23 +01:00
|
|
|
# ${GH_TOKEN} is defined as a secure variable inside .travis.yml
|
2015-12-04 15:54:05 +01:00
|
|
|
git clone --quiet --depth 1 https://${GH_TOKEN}@${SITE_URL} $SITE_HOME
|
|
|
|
mv -f $TLDR_ARCHIVE $SITE_HOME/assets/
|
|
|
|
cp -f $TLDRHOME/pages/index.json $SITE_HOME/assets/
|
|
|
|
|
|
|
|
cd $SITE_HOME
|
2017-09-12 12:11:28 +02:00
|
|
|
git add -A
|
2015-12-04 15:54:05 +01:00
|
|
|
git commit -m "[TravisCI] uploaded assets after commits ${TRAVIS_COMMIT_RANGE}"
|
2015-12-05 00:09:18 +01:00
|
|
|
git push -q
|
2015-12-04 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# MAIN
|
|
|
|
###################################
|
|
|
|
|
|
|
|
if [ ! "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
|
|
|
echo "This is a Pull Request, no index rebuild needed"
|
|
|
|
elif [ ! "$TRAVIS_BRANCH" == "master" ]; then
|
|
|
|
echo "This is not a master branch, no index rebuild needed"
|
|
|
|
else
|
|
|
|
initialize
|
2015-12-05 00:09:18 +01:00
|
|
|
rebuild_index && echo "Rebuilding index is done"
|
|
|
|
build_archive && echo "Pages archive is created"
|
|
|
|
upload_assets && echo "Assets (pages archive, index) deployed to static site"
|
2015-12-04 15:54:05 +01:00
|
|
|
fi
|