Skip to content

Commit a1a6dfa

Browse files
berquistleios
authored andcommitted
Use Travis CI to test the book build and then deploy it to the site, take 2 (#316)
* Use Travis CI to test the book build and then deploy it to the site. * A CNAME file is needed for the correct URL redirect. * Disable caching Node modules for Travis
1 parent 7994074 commit a1a6dfa

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
- env | sort
22+
- |
23+
if [[ "${TRAVIS_BRANCH}" == master && "${TRAVIS_PULL_REQUEST}" == false ]]; then
24+
# Commits to master that are not pull requests, that is, only
25+
# actual addition of code to master, should deploy the book to
26+
# the site.
27+
bash "${TRAVIS_BUILD_DIR}"/tools/deploy/update_site_travis.bash
28+
fi

tools/deploy/update_site_travis.bash

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
# - DOCS_REPO_NAME: name of the remote repo
11+
# - DOCS_REPO_OWNER: name of the remote repo's owner
12+
# - GH_TOKEN: [secret] Personal Access Token
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 ${DOCS_REPO_NAME+x} ]; then
21+
echo "${bold}\$DOCS_REPO_NAME is not set!${normal}"
22+
exit 1
23+
elif [ -z ${DOCS_REPO_OWNER+x} ]; then
24+
echo "${bold}\$DOCS_REPO_OWNER is not set!${normal}"
25+
exit 1
26+
elif [ -z ${GH_TOKEN+x} ]; then
27+
echo "${bold}\$GH_TOKEN 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/${DOCS_REPO_OWNER}/${DOCS_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 ./"${DOCS_REPO_NAME}"/*
43+
cp -a ./build/* ./"${DOCS_REPO_NAME}"
44+
pushd ./"${DOCS_REPO_NAME}"
45+
echo "www.algorithm-archive.org" > CNAME
46+
echo "${bold}Adding changes...${normal}"
47+
git add --all
48+
echo "${bold}Committing...${normal}"
49+
# This will return 1 if there are no changes, which should not
50+
# result in failure.
51+
git commit \
52+
-m "Deploy book to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" \
53+
-m "Commit: ${TRAVIS_COMMIT}" || ret=$?
54+
git push "https://${GH_TOKEN}@${GH_REPO_REF}"
55+
popd
56+
else
57+
echo "" >&2
58+
echo "${bold}Warning: The book wasn't found!${normal}" >&2
59+
echo "${bold}Warning: Not going to push the book to GitHub!${normal}" >&2
60+
exit 1
61+
fi

0 commit comments

Comments
 (0)