1#!/bin/sh 2set -x 3################################################################################ 4# Title : generateDocumentationAndDeploy.sh 5# Date created : 16Nov2018 6# Original Author: "Jeroen de Bruijn" 7# based on https://gist.github.com/vidavidorra/548ffbcdae99d752da02 8# 9# Preconditions: 10# - Packages doxygen graphviz must be installed. 11# - An gh-pages branch should already exist. See below for mor info on how to 12# create a gh-pages branch. 13# 14# Required global variables: 15# - GH_DOC_TOKEN : Secure token to the github repository. 16# 17# This script will generate Doxygen documentation and push the documentation to 18# the gh-pages branch of a repository specified by $TRAVIS_REPO_SLUG 19# Before this script is used there should already be a gh-pages branch in the 20# repository. 21# 22# This file is processed by CMAKE to get the version in the commit message 23# 24################################################################################ 25 26##### Setup this script and get the current gh-pages branch. 27echo 'Setting up the script...' 28GH_REPO_NAME=$(echo $TRAVIS_REPO_SLUG | awk -F/ '{print $2}') 29 30# Exit with nonzero exit code if anything fails 31set -e 32 33# by the time this script is run, we should have already made the docs 34cd $TRAVIS_BUILD_DIR/build 35#docs should be in the $TRAVIS_BUILD_DIR/build/html directory 36if [ ! -d "html" ] || [ ! -f "./html/index.html" ]; then 37 echo '' >&2 38 echo 'Warning: No documentation (html) files have been found!' >&2 39 echo 'Warning: Not going to push the documentation to GitHub!' >&2 40 exit 0 41fi 42 43if [ -z "${TRAVIS_TAG}" ] ; then 44 echo 'Warning: Not a tag' >&2 45 echo 'Warning: Not going to push the documentation to GitHub!' >&2 46 exit 0 47fi 48 49# Get the current gh-pages branch 50git clone -b gh-pages https://git@github.com/$TRAVIS_REPO_SLUG 51cd $GH_REPO_NAME 52 53# Remove everything currently in the gh-pages branch. 54# GitHub is smart enough to know which files have changed and which files have 55# stayed the same and will only update the changed files. So the gh-pages branch 56# can be safely cleaned, and it is sure that everything pushed later is the new 57# documentation. 58rm -rf * 59 60#copy the files over 61cp -a ../html/* ./ 62 63##### Configure git. 64# Set the push default to simple i.e. push only the current branch. 65git config --global push.default simple 66# Pretend to be an user called Travis CI. 67git config user.name "Autogenerated by Travis CI" 68git config user.email "robin.getz@analog.com" 69 70# Need to create a .nojekyll file to allow filenames starting with an underscore 71# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file. 72# Presumably this is only needed when the SHORT_NAMES option in Doxygen is set 73# to NO, which it is by default. So creating the file just in case. 74if [ ! -f ".nojekyll" ] ; then 75 touch .nojekyll 76fi 77 78################################################################################ 79##### Upload the documentation to the gh-pages branch of the repository. ##### 80 81echo 'Uploading documentation to the gh-pages branch...' 82# Add everything in this directory (the Doxygen code documentation) to the 83# gh-pages branch. 84# 85# GitHub is smart enough to know which files have changed and which files have 86# stayed the same and will only update the changed files. 87git add --all 88 89# Commit the added files with a title and description containing the Travis CI 90# build number and the GitHub commit reference that issued this build. 91git commit -m "Deploy autogenerated docs for ${GH_REPO_NAME} v@LIBIIO_VERSION_MAJOR@.@LIBIIO_VERSION_MINOR@-g@LIBIIO_VERSION_GIT@" --sign 92 93# Force push to the remote gh-pages branch. 94# The ouput is redirected to /dev/null to hide any sensitive credential data 95# that might otherwise be exposed. 96git push --force "https://${GH_DOC_TOKEN}@github.com/${TRAVIS_REPO_SLUG}" > /dev/null 2>&1 97 98