Created
July 25, 2018 05:47
-
-
Save akshatamohanty/687128aa215783c51a680b8485118e7b to your computer and use it in GitHub Desktop.
Custom Script to publish a gitbook to gh-pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| function exit_on_error(){ | |
| echo $1 | |
| git add . | |
| git stash | |
| git stash drop | |
| echo 'moving to master' | |
| git checkout master | |
| exit 1 | |
| } | |
| # git config core.sparseCheckout true || exit_on_error "sparseCheckout failed" && \ | |
| gitbook build || exit_on_error 'error-building' \ | |
| && git checkout gh-pages && echo 'in-gh-pages' || exit_on_error "error checking out" \ | |
| && find . -maxdepth 1 ! -name '.git' -and ! -name '_book' -and ! -name '.gitignore' -and ! -name '.' -exec rm -r -f {} + && echo 'deleted-previous-version' || exit_on_error 'deleting-previous-version-failed' \ | |
| && cp -r ./_book/* ./ && echo 'extracted-files' || exit_on_error 'error-copying' \ | |
| && rm -R _book || exit_on_error 'error-copying' \ | |
| && git add . && git commit -m"Automated Build Complete" || exit_on_error 'error-committing-build' \ | |
| && git checkout master && echo 'build-complete' || exit_on_error 'error-shifting-to-master' | |
| # build gitbook :: gitbook build | |
| # checkout gh-pages branch :: git checkout gh-pages | |
| # delete all folders and files except .git and _book and .gitignore :: find . -maxdepth 1 ! -name '.git' -and ! -name '_book' -and ! -name '.gitignore' -exec rm -r -f {} + | |
| # extract all contents from _book :: cp -r ./_book/* ./ | |
| # delete empty _book folder :: rm -R _book | |
| # delete build script :: rm script.sh | |
| # commit the changes :: git add . && git commit -m"Automated Build Complete" | |
| # push to gh-pages :: git push urban-prototyping gh-pages | |
| # this script gets triggered when changes are pushed to master branch | |
| # trigger using travis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment