Skip to content

Commit a876ea3

Browse files
berquistleios
authored andcommitted
Automatically build book and deploy to a repo (#284)
* Use Travis to test building the book. * Add script to deploy the book to a separate repo. * Make messages bold; fix duplicate word
1 parent 3613e2d commit a876ea3

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
dist: trusty
2+
sudo: false
3+
4+
language: node_js
5+
node_js:
6+
- "4"
7+
8+
cache:
9+
directories:
10+
- node_modules
11+
12+
install:
13+
- npm install gitbook-cli -g
14+
- gitbook install
15+
16+
before_script:
17+
- mkdir -p "${TRAVIS_BUILD_DIR}"/build
18+
19+
script:
20+
- gitbook build . "${TRAVIS_BUILD_DIR}"/build
21+
- |
22+
if [[ "${TRAVIS_BRANCH}" == master ]]; then
23+
bash "${TRAVIS_BUILD_DIR}"/tools/deploy/update_site_travis.bash
24+
fi

tools/deploy/update_site_travis.bash

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# update_site_travis.bash: Update a GitHub repo with the book build
4+
# products.
5+
6+
set -o errexit
7+
8+
# Required environment variables:
9+
# - DOCS_BRANCH_NAME: name of the remote branch serving the book
10+
# - GH_REPO_NAME: name of the remote repo
11+
# - GH_TOKEN: [secret] Personal Access Token
12+
# - GH_USER: name of the remote repo's owner
13+
14+
bold=$(tput bold)
15+
normal=$(tput sgr0)
16+
17+
if [ -z ${DOCS_BRANCH_NAME+x} ]; then
18+
echo "${bold}\$DOCS_BRANCH_NAME is not set!${normal}"
19+
exit 1
20+
elif [ -z ${GH_REPO_NAME+x} ]; then
21+
echo "${bold}\$GH_REPO_NAME is not set!${normal}"
22+
exit 1
23+
elif [ -z ${GH_TOKEN+x} ]; then
24+
echo "${bold}\$GH_TOKEN is not set!${normal}"
25+
exit 1
26+
elif [ -z ${GH_USER+x} ]; then
27+
echo "${bold}\$GH_USER is not set!${normal}"
28+
exit 1
29+
fi
30+
31+
git config user.name "Travis CI User"
32+
git config user.email "travis@travis-ci.org"
33+
34+
GH_REPO_REF="github.com/${GH_USER}/${GH_REPO_NAME}.git"
35+
36+
# Assume the book has already been built, and was moved to `build/`
37+
# inside the same directory as this script.
38+
39+
if [ -d build ]; then
40+
echo "${bold}Cloning the website repo...${normal}"
41+
git clone -b $DOCS_BRANCH_NAME https://git@${GH_REPO_REF}
42+
rm -rf ./"${GH_REPO_NAME}"/*
43+
cp -a ./build/* ./"${GH_REPO_NAME}"
44+
pushd ./"${GH_REPO_NAME}"
45+
echo "${bold}Adding changes...${normal}"
46+
git add --all
47+
echo "${bold}Committing...${normal}"
48+
# This will return 1 if there are no changes, which should not
49+
# result in failure.
50+
git commit \
51+
-m "Deploy book to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" \
52+
-m "Commit: ${TRAVIS_COMMIT}" || ret=$?
53+
git push --force "https://${GH_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1
54+
popd
55+
else
56+
echo "" >&2
57+
echo "${bold}Warning: The book wasn't found!${normal}" >&2
58+
echo "${bold}Warning: Not going to push the book to GitHub!${normal}" >&2
59+
exit 1
60+
fi

0 commit comments

Comments
 (0)