| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# deploy_docs_travis.bash: Deploy the documentation to the website using |
| 4 |
# Travis. Assume that the documentation has already been built. |
| 5 |
|
| 6 |
# Adapted from https://gist.github.com/vidavidorra/548ffbcdae99d752da02 |
| 7 |
|
| 8 |
set -o errexit |
| 9 |
|
| 10 |
# Required environment variables: |
| 11 |
# - DOCS_BRANCH_NAME: name of the remote branch serving the book |
| 12 |
# - DOCS_BUILD_DIR: directory where documentation HTML files live |
| 13 |
# - DOCS_REPO_NAME: name of the remote repo |
| 14 |
# - DOCS_REPO_OWNER: name of the remote repo's owner |
| 15 |
# - GH_TOKEN: [secret] Personal Access Token |
| 16 |
|
| 17 |
bold=$(tput bold) |
| 18 |
normal=$(tput sgr0) |
| 19 |
|
| 20 |
if [ -z ${DOCS_BRANCH_NAME+x} ]; then |
| 21 |
echo "${bold}\$DOCS_BRANCH_NAME is not set!${normal}" |
| 22 |
exit 1 |
| 23 |
elif [ -z ${DOCS_BUILD_DIR+x} ]; then |
| 24 |
echo "${bold}\$DOCS_BUILD_DIR is not set!${normal}" |
| 25 |
exit 1 |
| 26 |
elif [ -z ${DOCS_REPO_NAME+x} ]; then |
| 27 |
echo "${bold}\$DOCS_REPO_NAME is not set!${normal}" |
| 28 |
exit 1 |
| 29 |
elif [ -z ${DOCS_REPO_OWNER+x} ]; then |
| 30 |
echo "${bold}\$DOCS_REPO_OWNER is not set!${normal}" |
| 31 |
exit 1 |
| 32 |
elif [ -z ${GH_TOKEN+x} ]; then |
| 33 |
echo "${bold}\$GH_TOKEN is not set!${normal}" |
| 34 |
exit 1 |
| 35 |
fi |
| 36 |
|
| 37 |
git config user.name "Travis CI User" |
| 38 |
git config user.email "[email protected]" |
| 39 |
|
| 40 |
GH_REPO_REF="github.com/${DOCS_REPO_OWNER}/${DOCS_REPO_NAME}.git" |
| 41 |
|
| 42 |
git clone -b "${DOCS_BRANCH_NAME}" https://git@"${GH_REPO_REF}" |
| 43 |
pushd ./"${DOCS_REPO_NAME}" |
| 44 |
rm -rf ./* |
| 45 |
echo "Copying built HTML..." |
| 46 |
cp -a "${DOCS_BUILD_DIR}"/* . |
| 47 |
|
| 48 |
if [ -f "index.html" ]; then |
| 49 |
echo "" > .nojekyll |
| 50 |
echo "${bold}Adding changes...${normal}" |
| 51 |
git add --all |
| 52 |
echo "${bold}Committing...${normal}" |
| 53 |
# This will return 1 if there are no changes, which should not result in |
| 54 |
# failure. |
| 55 |
git commit \ |
| 56 |
-m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" \ |
| 57 |
-m "Commit: ${TRAVIS_COMMIT}" || ret=$? |
| 58 |
git push "https://${GH_TOKEN}@${GH_REPO_REF}" |
| 59 |
else |
| 60 |
echo "" >&2 |
| 61 |
echo "${bold}Warning: No documentation (html) files have been found!${normal}" >&2 |
| 62 |
echo "${bold}Warning: Not going to push the documentation to GitHub!${normal}" >&2 |
| 63 |
exit 1 |
| 64 |
fi |
| 65 |
|
| 66 |
popd |