diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..c212e7863 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +dist: trusty +sudo: false + +language: node_js +node_js: + - "4" + +# cache: +# directories: +# - node_modules + +install: + - npm install gitbook-cli -g + - gitbook install + +before_script: + - mkdir -p "${TRAVIS_BUILD_DIR}"/build + +script: + - gitbook build . "${TRAVIS_BUILD_DIR}"/build + - env | sort + - | + if [[ "${TRAVIS_BRANCH}" == master && "${TRAVIS_PULL_REQUEST}" == false ]]; then + # Commits to master that are not pull requests, that is, only + # actual addition of code to master, should deploy the book to + # the site. + bash "${TRAVIS_BUILD_DIR}"/tools/deploy/update_site_travis.bash + fi diff --git a/tools/deploy/update_site_travis.bash b/tools/deploy/update_site_travis.bash new file mode 100644 index 000000000..cd923d985 --- /dev/null +++ b/tools/deploy/update_site_travis.bash @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# update_site_travis.bash: Update a GitHub repo with the book build +# products. + +set -o errexit + +# Required environment variables: +# - DOCS_BRANCH_NAME: name of the remote branch serving the book +# - DOCS_REPO_NAME: name of the remote repo +# - DOCS_REPO_OWNER: name of the remote repo's owner +# - GH_TOKEN: [secret] Personal Access Token + +bold=$(tput bold) +normal=$(tput sgr0) + +if [ -z ${DOCS_BRANCH_NAME+x} ]; then + echo "${bold}\$DOCS_BRANCH_NAME is not set!${normal}" + exit 1 +elif [ -z ${DOCS_REPO_NAME+x} ]; then + echo "${bold}\$DOCS_REPO_NAME is not set!${normal}" + exit 1 +elif [ -z ${DOCS_REPO_OWNER+x} ]; then + echo "${bold}\$DOCS_REPO_OWNER is not set!${normal}" + exit 1 +elif [ -z ${GH_TOKEN+x} ]; then + echo "${bold}\$GH_TOKEN is not set!${normal}" + exit 1 +fi + +git config user.name "Travis CI User" +git config user.email "travis@travis-ci.org" + +GH_REPO_REF="github.com/${DOCS_REPO_OWNER}/${DOCS_REPO_NAME}.git" + +# Assume the book has already been built, and was moved to `build/` +# inside the same directory as this script. + +if [ -d build ]; then + echo "${bold}Cloning the website repo...${normal}" + git clone -b "${DOCS_BRANCH_NAME}" https://git@"${GH_REPO_REF}" + rm -rf ./"${DOCS_REPO_NAME}"/* + cp -a ./build/* ./"${DOCS_REPO_NAME}" + pushd ./"${DOCS_REPO_NAME}" + echo "www.algorithm-archive.org" > CNAME + echo "${bold}Adding changes...${normal}" + git add --all + echo "${bold}Committing...${normal}" + # This will return 1 if there are no changes, which should not + # result in failure. + git commit \ + -m "Deploy book to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" \ + -m "Commit: ${TRAVIS_COMMIT}" || ret=$? + git push "https://${GH_TOKEN}@${GH_REPO_REF}" + popd +else + echo "" >&2 + echo "${bold}Warning: The book wasn't found!${normal}" >&2 + echo "${bold}Warning: Not going to push the book to GitHub!${normal}" >&2 + exit 1 +fi