blob: 929d1e0e6cf657911118f78f18e6cc24e1ee8a51 [file] [log] [blame]
Dean Troyer9b973672013-10-16 15:13:56 -05001#!/usr/bin/env bash
2
Dean Troyerb3fdb1c2014-11-17 12:45:09 -06003# **build_docs.sh** - Build the docs for DevStack
Dean Troyer9b973672013-10-16 15:13:56 -05004#
Dean Troyer54b97322014-06-20 17:53:55 -05005# - Install shocco if not found on PATH and INSTALL_SHOCCO is set
Dean Troyer9b973672013-10-16 15:13:56 -05006# - Clone MASTER_REPO branch MASTER_BRANCH
Monty Taylor0cbddea2014-10-07 13:25:01 -07007# - Re-creates ``doc/build/html`` directory from existing repo + new generated script docs
Dean Troyer9b973672013-10-16 15:13:56 -05008
9# Usage:
Dean Troyerb3fdb1c2014-11-17 12:45:09 -060010## build_docs.sh [-o <out-dir>]
Dean Troyer54b97322014-06-20 17:53:55 -050011## -o <out-dir> Write the static HTML output to <out-dir>
12## (Note that <out-dir> will be deleted and re-created to ensure it is clean)
Dean Troyer9b973672013-10-16 15:13:56 -050013
14# Defaults
15# --------
16
Monty Taylor0cbddea2014-10-07 13:25:01 -070017HTML_BUILD=doc/build/html
Dean Troyer54b97322014-06-20 17:53:55 -050018
Dean Troyerc04ddbe2013-11-06 02:15:11 -060019# Keep track of the devstack directory
20TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
21
Dean Troyer9b973672013-10-16 15:13:56 -050022# Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
23SHOCCO=${SHOCCO:-shocco}
24if ! which shocco; then
Dean Troyerc04ddbe2013-11-06 02:15:11 -060025 if [[ ! -x $TOP_DIR/shocco/shocco ]]; then
Dean Troyer9b973672013-10-16 15:13:56 -050026 if [[ -z "$INSTALL_SHOCCO" ]]; then
27 echo "shocco not found in \$PATH, please set environment variable SHOCCO"
28 exit 1
29 fi
30 echo "Installing local copy of shocco"
Dean Troyerc04ddbe2013-11-06 02:15:11 -060031 if ! which pygmentize; then
32 sudo pip install Pygments
33 fi
34 if ! which rst2html.py; then
35 sudo pip install docutils
36 fi
Dean Troyer9b973672013-10-16 15:13:56 -050037 git clone -b rst_support https://github.com/dtroyer/shocco shocco
38 cd shocco
39 ./configure
Dean Troyer54b97322014-06-20 17:53:55 -050040 make || exit
Dean Troyer9b973672013-10-16 15:13:56 -050041 cd ..
42 fi
Dean Troyerc04ddbe2013-11-06 02:15:11 -060043 SHOCCO=$TOP_DIR/shocco/shocco
Dean Troyer9b973672013-10-16 15:13:56 -050044fi
45
46# Process command-line args
Dean Troyerb3fdb1c2014-11-17 12:45:09 -060047while getopts o: c; do
Dean Troyer9b973672013-10-16 15:13:56 -050048 case $c in
Dean Troyer54b97322014-06-20 17:53:55 -050049 o) HTML_BUILD=$OPTARG
Dean Troyer9b973672013-10-16 15:13:56 -050050 ;;
51 esac
52done
53shift `expr $OPTIND - 1`
54
Dean Troyer54b97322014-06-20 17:53:55 -050055
Dean Troyer9b973672013-10-16 15:13:56 -050056# Processing
57# ----------
58
Dean Troyerb3fdb1c2014-11-17 12:45:09 -060059# Ensure build dir exists
Dean Troyer54b97322014-06-20 17:53:55 -050060mkdir -p $HTML_BUILD
Dean Troyer9b973672013-10-16 15:13:56 -050061
Dean Troyer54b97322014-06-20 17:53:55 -050062# Get fully qualified dirs
Dean Troyer54b97322014-06-20 17:53:55 -050063FQ_HTML_BUILD=$(cd $HTML_BUILD && pwd)
64
Dean Troyer926c99d2014-07-01 20:46:04 -050065# Insert automated bits
66GLOG=$(mktemp gitlogXXXX)
Dean Troyerb3fdb1c2014-11-17 12:45:09 -060067echo "<ul>" >$GLOG
Dean Troyer926c99d2014-07-01 20:46:04 -050068git log \
69 --pretty=format:' <li>%s - <em>Commit <a href="https://review.openstack.org/#q,%h,n,z">%h</a> %cd</em></li>' \
70 --date=short \
Dean Troyerb3fdb1c2014-11-17 12:45:09 -060071 --since '6 months ago' | grep -v Merge >>$GLOG
72echo "</ul>" >>$GLOG
73sed -i~ -e $"/^.*%GIT_LOG%.*$/r $GLOG" -e $"/^.*%GIT_LOG%.*$/s/^.*%GIT_LOG%.*$//" $FQ_HTML_BUILD/changes.html
Dean Troyer926c99d2014-07-01 20:46:04 -050074rm -f $GLOG
75
Dean Troyer9b973672013-10-16 15:13:56 -050076# Build list of scripts to process
77FILES=""
78for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
79 echo $f
80 FILES+="$f "
Dean Troyer54b97322014-06-20 17:53:55 -050081 mkdir -p $FQ_HTML_BUILD/`dirname $f`;
82 $SHOCCO $f > $FQ_HTML_BUILD/$f.html
Dean Troyer9b973672013-10-16 15:13:56 -050083done
Dean Troyer54b97322014-06-20 17:53:55 -050084for f in $(find functions functions-common lib samples -type f -name \*); do
Dean Troyer9b973672013-10-16 15:13:56 -050085 echo $f
86 FILES+="$f "
Dean Troyer54b97322014-06-20 17:53:55 -050087 mkdir -p $FQ_HTML_BUILD/`dirname $f`;
88 $SHOCCO $f > $FQ_HTML_BUILD/$f.html
Dean Troyer9b973672013-10-16 15:13:56 -050089done
Monty Taylor0cbddea2014-10-07 13:25:01 -070090echo "$FILES" >doc/files
Dean Troyer9b973672013-10-16 15:13:56 -050091
Dean Troyer9b973672013-10-16 15:13:56 -050092# Clean up or report the temp workspace
93if [[ -n REPO && -n $PUSH_REPO ]]; then
Dean Troyer54b97322014-06-20 17:53:55 -050094 echo rm -rf $TMP_ROOT
Dean Troyer9b973672013-10-16 15:13:56 -050095else
96 if [[ -z "$TMP_ROOT" ]]; then
97 TMP_ROOT="$(pwd)"
98 fi
Dean Troyer54b97322014-06-20 17:53:55 -050099 echo "Built docs in $HTML_BUILD"
Dean Troyer9b973672013-10-16 15:13:56 -0500100fi