2015-12-04 14:54:05 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-02-04 13:59:17 +00:00
|
|
|
# This script is executed by Travis CI when a PR is merged (i.e. in the `deploy` step).
|
2019-02-04 22:34:33 +00:00
|
|
|
set -ex
|
2015-12-04 14:54:05 +00:00
|
|
|
|
|
|
|
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"
|
2019-02-03 13:57:35 +00:00
|
|
|
export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
|
2015-12-04 14:54:05 +00:00
|
|
|
|
2019-02-04 13:59:17 +00:00
|
|
|
# Configure git.
|
2015-12-04 14:54:05 +00:00
|
|
|
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"
|
2019-02-04 13:59:17 +00:00
|
|
|
|
|
|
|
# Decrypt and add deploy key.
|
|
|
|
eval "$(ssh-agent -s)"
|
|
|
|
openssl aes-256-cbc -K $encrypted_973441be79af_key -iv $encrypted_973441be79af_iv -in ./scripts/id_ed25519_tldr_asset_upload.enc -out id_ed25519 -d
|
|
|
|
chmod 600 id_ed25519
|
|
|
|
ssh-add id_ed25519
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function rebuild_index {
|
2016-01-19 19:44:37 +00:00
|
|
|
npm run build-index
|
2019-02-04 22:34:33 +00:00
|
|
|
echo "Rebuilding index done."
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_archive {
|
|
|
|
rm -f $TLDR_ARCHIVE
|
|
|
|
cd $TLDRHOME/
|
2019-04-02 19:37:53 +01:00
|
|
|
zip -r $TLDR_ARCHIVE pages*/ LICENSE.md index.json
|
2019-02-04 22:34:33 +00:00
|
|
|
echo "Pages archive created."
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload_assets {
|
2019-02-03 13:57:35 +00:00
|
|
|
git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git $SITE_HOME
|
2015-12-04 14:54:05 +00:00
|
|
|
mv -f $TLDR_ARCHIVE $SITE_HOME/assets/
|
2019-04-02 19:37:53 +01:00
|
|
|
cp -f $TLDRHOME/index.json $SITE_HOME/assets/
|
2015-12-04 14:54:05 +00:00
|
|
|
|
|
|
|
cd $SITE_HOME
|
2019-02-03 13:57:35 +00:00
|
|
|
git add -A
|
2015-12-04 14:54:05 +00:00
|
|
|
git commit -m "[TravisCI] uploaded assets after commits ${TRAVIS_COMMIT_RANGE}"
|
2015-12-04 23:09:18 +00:00
|
|
|
git push -q
|
2019-02-04 22:34:33 +00:00
|
|
|
|
|
|
|
echo "Assets (pages archive, index) deployed to static site."
|
2015-12-04 14:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# MAIN
|
|
|
|
###################################
|
|
|
|
|
2019-02-04 13:59:17 +00:00
|
|
|
initialize
|
2019-02-04 22:34:33 +00:00
|
|
|
rebuild_index
|
|
|
|
build_archive
|
|
|
|
upload_assets
|