Skip to content

Commit

Permalink
Publish the book to GitHub Pages via Travis CI
Browse files Browse the repository at this point in the history
  • Loading branch information
phrohdoh committed May 7, 2019
1 parent dfbcdfc commit 5b7786b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
language: node_js
dist: trusty
sudo: required

node_js:
- 'stable'

cache:
directories:
- ./src/node_modules/

before_install:
- sudo apt-get -qq update

install:
- npm install -g gitbook-cli

before_script:
- chmod u+x ./tools/travis-ci/build-and-tag.bash

script:
- ./tools/travis-ci/build-and-tag.bash

before_deploy:
- cd ${TRAVIS_BUILD_DIR}

deploy:
- provider: pages
skip_cleanup: true
github_token: ${GITHUB_TOKEN}
local_dir: ./src/_book/
target_branch: gh-pages
on:
branch: master

branches:
only:
- master
43 changes: 43 additions & 0 deletions tools/travis-ci/build-and-tag.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# *must* be invoked from the root of the repository (with no args)

# shell color constants
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
CLEAR='\033[0m'

BUILD_NAME="openra-book-v${TRAVIS_BUILD_NUMBER}"

# print all the travis env vars to the console for debugging
echo -e "TRAVIS_BUILD_NUMBER: [${GREEN}${TRAVIS_BUILD_NUMBER}${CLEAR}]"
echo -e "TRAVIS_COMMIT: [${GREEN}${TRAVIS_COMMIT}${CLEAR}]"
echo -e "TRAVIS_BRANCH: [${GREEN}${TRAVIS_BRANCH}${CLEAR}]"
echo -e "TRAVIS_TAG: [${GREEN}${TRAVIS_TAG}${CLEAR}]"
echo -e "TRAVIS_PULL_REQUEST: [${GREEN}${TRAVIS_PULL_REQUEST}${CLEAR}]"
echo -e "TRAVIS_EVENT_TYPE: [${GREEN}${TRAVIS_EVENT_TYPE}${CLEAR}]"
echo -e "BUILD_NAME: [${GREEN}${BUILD_NAME}${CLEAR}]"

# build the book
echo -e "${GREEN}building the book${CLEAR}"
cd ./src/
gitbook install
gitbook build

# remove unwanted files from the book
echo -e "${GREEN}removing unwanted files{$CLEAR}"
rm -v _book/.travis.yml
rm -v _book/*.yml
rm -v _book/*.bash

# if this is a build of 'master' then create & push a new git tag
if [[ "${TRAVIS_BRANCH}" == "master" ]]; then
git config --global user.email 'orabot@openra.net'
git config --global user.name 'orabot'

echo -e "${RED}todo: implement this${CLEAR}"
else
echo -e "${GREEN}branch is not 'master' so skipping git tag creation"
fi

0 comments on commit 5b7786b

Please sign in to comment.