-
Notifications
You must be signed in to change notification settings - Fork 51
/
.travis.docgen.sh
31 lines (24 loc) · 1.13 KB
/
.travis.docgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# From https://github.com/simonjbeaumont/ocaml-travis-gh-pages
if [[ -z "$TRAVIS" || "$TRAVIS_PULL_REQUEST" != "false" || "$TRAVIS_BRANCH" != "master" ]]; then
echo "[docgen] This is not a push-to-master Travis build, doing nothing..."
exit 0
else
echo "[docgen] Updating docs on Github pages..."
fi
DOCSRC=$(opam config var ${PACKAGE}:build)/_build/default/_doc
DOCDIR=.gh-pages
if [ -n "$KEEP" ]; then trap "rm -rf $DOCDIR" EXIT; fi
rm -rf $DOCDIR
# Error out if $GH_TOKEN is empty or unset
: ${GH_TOKEN:?"GH_TOKEN need to be uploaded via travis-encrypt"}
git clone https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} $DOCDIR 2>&1 | sed -e "s/$GH_TOKEN/!REDACTED!/g"
git -C $DOCDIR checkout gh-pages || git -C $DOCDIR checkout --orphan gh-pages
DOCFILES=$(echo $DOCSRC/*)
cp -R $DOCFILES $DOCDIR
git -C $DOCDIR config user.email "[email protected]"
git -C $DOCDIR config user.name "Travis"
git -C $DOCDIR add .
git -C $DOCDIR commit --allow-empty -m "Travis build $TRAVIS_BUILD_NUMBER pushed docs to gh-pages"
git -C $DOCDIR push origin gh-pages 2>&1 | sed -e "s/$GH_TOKEN/!REDACTED!/g"
echo "[docgen] updated docs successfully!"