From e0584aedc8a64108a6eaa6998e23aa1d26b0fa19 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Fri, 20 Jul 2018 22:13:14 -0400 Subject: [PATCH 1/3] Use Travis to test building the book. --- .travis.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..fd36ac8f2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +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 From 065e1efd1138cdb3f73c56882ebc27aa06ec5643 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Fri, 20 Jul 2018 23:17:03 -0400 Subject: [PATCH 2/3] Add script to deploy the book to a separate repo. --- .travis.yml | 4 ++ tools/deploy/update_site_travis.bash | 57 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tools/deploy/update_site_travis.bash diff --git a/.travis.yml b/.travis.yml index fd36ac8f2..fc9f0e4fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,3 +18,7 @@ before_script: script: - gitbook build . "${TRAVIS_BUILD_DIR}"/build + - | + if [[ "${TRAVIS_BRANCH}" == master ]]; then + 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..c8a453a07 --- /dev/null +++ b/tools/deploy/update_site_travis.bash @@ -0,0 +1,57 @@ +#!/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 +# - GH_REPO_NAME: name of the remote repo +# - GH_USER: name of the remote repo's owner +# - GH_TOKEN: [secret] Personal Access Token + +if [ -z ${DOCS_BRANCH_NAME+x} ]; then + echo "\$DOCS_BRANCH_NAME is not set!" + exit 1 +elif [ -z ${GH_REPO_NAME+x} ]; then + echo "\$GH_REPO_NAME is not set!" + exit 1 +elif [ -z ${GH_TOKEN+x} ]; then + echo "\$GH_TOKEN is not set!" + exit 1 +elif [ -z ${GH_USER+x} ]; then + echo "\$GH_USER is not set!" + exit 1 +fi + +git config user.name "Travis CI User" +git config user.email "travis@travis-ci.org" + +GH_REPO_REF="github.com/${GH_USER}/${GH_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 "Cloning the website repo..." + git clone -b $DOCS_BRANCH_NAME https://git@${GH_REPO_REF} + rm -rf ./"${GH_REPO_NAME}"/* + cp -a ./build/* ./"${GH_REPO_NAME}" + pushd ./"${GH_REPO_NAME}" + echo "Adding changes..." + git add --all + echo "Committing..." + # 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 --force "https://${GH_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1 + popd +else + echo "" >&2 + echo "Warning: The book wasn't found found!" >&2 + echo "Warning: Not going to push the book to GitHub!" >&2 + exit 1 +fi From 7d3f676b71c8d4ba18eb9b62135256032403fbeb Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Sat, 21 Jul 2018 23:14:22 -0400 Subject: [PATCH 3/3] Make messages bold; fix duplicate word --- tools/deploy/update_site_travis.bash | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/deploy/update_site_travis.bash b/tools/deploy/update_site_travis.bash index c8a453a07..acf79f190 100644 --- a/tools/deploy/update_site_travis.bash +++ b/tools/deploy/update_site_travis.bash @@ -8,20 +8,23 @@ set -o errexit # Required environment variables: # - DOCS_BRANCH_NAME: name of the remote branch serving the book # - GH_REPO_NAME: name of the remote repo -# - GH_USER: name of the remote repo's owner # - GH_TOKEN: [secret] Personal Access Token +# - GH_USER: name of the remote repo's owner + +bold=$(tput bold) +normal=$(tput sgr0) if [ -z ${DOCS_BRANCH_NAME+x} ]; then - echo "\$DOCS_BRANCH_NAME is not set!" + echo "${bold}\$DOCS_BRANCH_NAME is not set!${normal}" exit 1 elif [ -z ${GH_REPO_NAME+x} ]; then - echo "\$GH_REPO_NAME is not set!" + echo "${bold}\$GH_REPO_NAME is not set!${normal}" exit 1 elif [ -z ${GH_TOKEN+x} ]; then - echo "\$GH_TOKEN is not set!" + echo "${bold}\$GH_TOKEN is not set!${normal}" exit 1 elif [ -z ${GH_USER+x} ]; then - echo "\$GH_USER is not set!" + echo "${bold}\$GH_USER is not set!${normal}" exit 1 fi @@ -34,14 +37,14 @@ GH_REPO_REF="github.com/${GH_USER}/${GH_REPO_NAME}.git" # inside the same directory as this script. if [ -d build ]; then - echo "Cloning the website repo..." + echo "${bold}Cloning the website repo...${normal}" git clone -b $DOCS_BRANCH_NAME https://git@${GH_REPO_REF} rm -rf ./"${GH_REPO_NAME}"/* cp -a ./build/* ./"${GH_REPO_NAME}" pushd ./"${GH_REPO_NAME}" - echo "Adding changes..." + echo "${bold}Adding changes...${normal}" git add --all - echo "Committing..." + echo "${bold}Committing...${normal}" # This will return 1 if there are no changes, which should not # result in failure. git commit \ @@ -51,7 +54,7 @@ if [ -d build ]; then popd else echo "" >&2 - echo "Warning: The book wasn't found found!" >&2 - echo "Warning: Not going to push the book to GitHub!" >&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