|
| 1 | +#!/bin/bash |
| 2 | +# Script to deploy documentation after successfull build of master branch or tag |
| 3 | +# If running under travis-ci this will automatically deploy updates to the master branch's |
| 4 | +# documentation on build events for the master branch, and will add/update documentation for |
| 5 | +# any new/updated tags that are pushed. |
| 6 | +# The script may also be used to manually deploy the current branch's documentation, |
| 7 | +# although for branch's other than master, index.html will likely need to be manually |
| 8 | +# edited to add an entry for the current branch. Also, this may be inadvisable, since the |
| 9 | +# the documentation can be published before the branch's code is published. Use it to add |
| 10 | +# new branch's development documentation, preferably immediately after pushing that branch |
| 11 | +# to github. |
| 12 | +set -ev # Echo what we're doing and fail on any errors |
| 13 | +if [ ! "$TRAVIS" ]; then #not on travis, try a sane deploy of current branch's documentation |
| 14 | + if [ "$(ls -A ./documentation)" ]; then #not empty |
| 15 | + REVISION="$(git rev-parse HEAD)" |
| 16 | + BRANCH="$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')" |
| 17 | + git clone --branch=gh-pages [email protected]:jacobwilliams/json-fortran.git gh-pages |
| 18 | + cd gh-pages |
| 19 | + [ -e "$BRANCH" ] && rm -r "$BRANCH" # wipe out old docs if they exist |
| 20 | + mkdir "$BRANCH" |
| 21 | + for f in ../documentation/*.*; do # add branch info to header and clean line endings |
| 22 | + sed '/[^#]robo_top_of_doc/ s;jsonfortran</a>;jsonfortran '"$BRANCH"'</a>;' $f | sed 's/ *$//' > "$BRANCH/${f##*/}" |
| 23 | + done |
| 24 | + git add "$BRANCH" |
| 25 | + git commit -m "Development documentation for $BRANCH updated for commit $REVISION" |
| 26 | + if egrep "\<${BRANCH}\>" index.html >/dev/null 2>&1 ; then |
| 27 | + echo "It appears that index.html knows about branch $BRANCH and likely does not require updating." |
| 28 | + git push origin gh-pages # assumes write access to jacobwilliams/json-fortran... |
| 29 | + # only true for @jacobwilliams |
| 30 | + else |
| 31 | + echo "index.html must be manually edited to add link to branch $BRANCH, then commit the changes and push manually." |
| 32 | + fi |
| 33 | + fi |
| 34 | +else #running under travis |
| 35 | + if $TRAVIS_SECURE_ENV_VARS ; then |
| 36 | + # only try to update master's development documentation |
| 37 | + if [ "$TRAVIS_BRANCH" = "master" ] && [ "$(ls -A $TRAVIS_BUILD_DIR/documentation)" ] ; then #not empty |
| 38 | + git clone --branch=gh-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG gh-pages |
| 39 | + cd gh-pages |
| 40 | + [ -e master ] && rm -r master # wipe out docs if they exist |
| 41 | + mkdir master |
| 42 | + for f in ../documentation/*.*; do # add branch info to header and clean line endings |
| 43 | + sed '/[^#]robo_top_of_doc/ s;jsonfortran</a>;jsonfortran master</a>;' $f | sed 's/ *$//' > master/${f##*/} |
| 44 | + done |
| 45 | + git add master |
| 46 | + git commit -m "Development documentation updated by travis job $TRAVIS_JOB_NUMBER for commits $TRAVIS_COMMIT_RANGE" |
| 47 | + git push origin gh-pages |
| 48 | + fi |
| 49 | + # If publishing a new/updated tag, deploy it's documentation |
| 50 | + if [ "$TRAVIS_TAG" ] && [ "$(ls -A $TRAVIS_BUILD_DIR/documentation)" ] ; then #not empty |
| 51 | + git clone --branch=gh-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG gh-pages |
| 52 | + cd gh-pages |
| 53 | + [ -e "$TRAVIS_TAG" ] && rm -r "$TRAVIS_TAG" # wipe out existing docs for tag if they exist |
| 54 | + mkdir "$TRAVIS_TAG" |
| 55 | + # Add an entry in index.html for the new tag, assume none exists |
| 56 | + awk '/<!--Next stable release goes here-->/{print "<a href=\"./'"$TRAVIS_TAG"'/masterindex.html\" class=\"indexitem\" >'"$TRAVIS_TAG"'</a>"}1' index.html > index2.html && mv index2.html index.html |
| 57 | + for f in ../documentation/*.*; do # add tag info to headers and clean line endings |
| 58 | + sed '/[^#]robo_top_of_doc/ s;jsonfortran</a>;jsonfortran '"$TRAVIS_TAG"'</a>;' $f | sed 's/ *$//' > "$TRAVIS_TAG/${f##*/}" |
| 59 | + done |
| 60 | + git add "$TRAVIS_TAG" index.html # don't forget to add the top level index! |
| 61 | + git commit -m "Tag/release documentation updated by travis job $TRAVIS_JOB_NUMBER for tag $TRAVIS_TAG $TRAVIS_COMMIT" |
| 62 | + git push origin gh-pages |
| 63 | + fi |
| 64 | + fi |
| 65 | +fi |
0 commit comments