blob: 77c2f4e02ec9f0c99a1a053ba82b6c8e3a57b659 [file] [log] [blame]
Dean Troyer9b973672013-10-16 15:13:56 -05001#!/usr/bin/env bash
2
3# **build_docs.sh** - Build the gh-pages docs for DevStack
4#
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
Dean Troyer54b97322014-06-20 17:53:55 -05007# - Re-creates ``docs/html`` directory from existing repo + new generated script docs
Dean Troyer9b973672013-10-16 15:13:56 -05008
9# Usage:
Dean Troyer54b97322014-06-20 17:53:55 -050010## build_docs.sh [-o <out-dir>] [-g] [master|<repo> [<branch>]]
11## <repo> The DevStack repository to clone (default is DevStack github repo)
Dean Troyer9b973672013-10-16 15:13:56 -050012## If a repo is not supplied use the current directory
13## (assumed to be a DevStack checkout) as the source.
Dean Troyer54b97322014-06-20 17:53:55 -050014## <branch> The DevStack branch to check out (default is master; ignored if
15## repo is not specified)
Dean Troyer9b973672013-10-16 15:13:56 -050016## . Use the current repo and branch (do not use with -p to
17## prevent stray files in the workspace being added tot he docs)
Dean Troyer54b97322014-06-20 17:53:55 -050018## -o <out-dir> Write the static HTML output to <out-dir>
19## (Note that <out-dir> will be deleted and re-created to ensure it is clean)
20## -g Update the old gh-pages repo (set PUSH=1 to actualy push up to RCB)
Dean Troyer9b973672013-10-16 15:13:56 -050021
22# Defaults
23# --------
24
25# Source repo/branch for DevStack
Sphoorti Joglekarce365ce2014-04-01 19:47:40 +053026MASTER_REPO=${MASTER_REPO:-git://git.openstack.org/openstack-dev/devstack}
Dean Troyer9b973672013-10-16 15:13:56 -050027MASTER_BRANCH=${MASTER_BRANCH:-master}
28
29# http://devstack.org is a GitHub gh-pages site in the https://github.com/cloudbuilders/devtack.git repo
30GH_PAGES_REPO=git@github.com:cloudbuilders/devstack.git
31
Dean Troyer54b97322014-06-20 17:53:55 -050032DOCS_SOURCE=docs/source
33HTML_BUILD=docs/html
34
Dean Troyerc04ddbe2013-11-06 02:15:11 -060035# Keep track of the devstack directory
36TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
37
Dean Troyer9b973672013-10-16 15:13:56 -050038# Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
39SHOCCO=${SHOCCO:-shocco}
40if ! which shocco; then
Dean Troyerc04ddbe2013-11-06 02:15:11 -060041 if [[ ! -x $TOP_DIR/shocco/shocco ]]; then
Dean Troyer9b973672013-10-16 15:13:56 -050042 if [[ -z "$INSTALL_SHOCCO" ]]; then
43 echo "shocco not found in \$PATH, please set environment variable SHOCCO"
44 exit 1
45 fi
46 echo "Installing local copy of shocco"
Dean Troyerc04ddbe2013-11-06 02:15:11 -060047 if ! which pygmentize; then
48 sudo pip install Pygments
49 fi
50 if ! which rst2html.py; then
51 sudo pip install docutils
52 fi
Dean Troyer9b973672013-10-16 15:13:56 -050053 git clone -b rst_support https://github.com/dtroyer/shocco shocco
54 cd shocco
55 ./configure
Dean Troyer54b97322014-06-20 17:53:55 -050056 make || exit
Dean Troyer9b973672013-10-16 15:13:56 -050057 cd ..
58 fi
Dean Troyerc04ddbe2013-11-06 02:15:11 -060059 SHOCCO=$TOP_DIR/shocco/shocco
Dean Troyer9b973672013-10-16 15:13:56 -050060fi
61
62# Process command-line args
Dean Troyer54b97322014-06-20 17:53:55 -050063while getopts go: c; do
Dean Troyer9b973672013-10-16 15:13:56 -050064 case $c in
Dean Troyer54b97322014-06-20 17:53:55 -050065 g) GH_UPDATE=1
Dean Troyer9b973672013-10-16 15:13:56 -050066 ;;
Dean Troyer54b97322014-06-20 17:53:55 -050067 o) HTML_BUILD=$OPTARG
Dean Troyer9b973672013-10-16 15:13:56 -050068 ;;
69 esac
70done
71shift `expr $OPTIND - 1`
72
Dean Troyer54b97322014-06-20 17:53:55 -050073
74if [[ -n "$1" ]]; then
75 master="master"
76 if [[ "${master/#$1}" != "master" ]]; then
77 # Partial match on "master"
Dean Troyer9b973672013-10-16 15:13:56 -050078 REPO=$MASTER_REPO
79 else
80 REPO=$1
81 fi
Dean Troyer54b97322014-06-20 17:53:55 -050082 REPO_BRANCH=${2:-$MASTER_BRANCH}
Dean Troyer9b973672013-10-16 15:13:56 -050083fi
84
85# Check out a specific DevStack branch
86if [[ -n $REPO ]]; then
87 # Make a workspace
Dean Troyer54b97322014-06-20 17:53:55 -050088 TMP_ROOT=$(mktemp -d work-docs-XXXX)
Dean Troyer9b973672013-10-16 15:13:56 -050089 echo "Building docs in $TMP_ROOT"
90 cd $TMP_ROOT
91
92 # Get the master branch
93 git clone $REPO devstack
94 cd devstack
Dean Troyer54b97322014-06-20 17:53:55 -050095 if [[ -n "$REPO_BRANCH" ]]; then
96 git checkout $REPO_BRANCH
97 fi
Dean Troyer9b973672013-10-16 15:13:56 -050098fi
99
Dean Troyer54b97322014-06-20 17:53:55 -0500100# Assumption is we are now in the DevStack workspace to be processed
101
Dean Troyer9b973672013-10-16 15:13:56 -0500102# Processing
103# ----------
104
Dean Troyer54b97322014-06-20 17:53:55 -0500105# Clean up build dir
106rm -rf $HTML_BUILD
107mkdir -p $HTML_BUILD
Dean Troyer9b973672013-10-16 15:13:56 -0500108
Dean Troyer54b97322014-06-20 17:53:55 -0500109# Get fully qualified dirs
110FQ_DOCS_SOURCE=$(cd $DOCS_SOURCE && pwd)
111FQ_HTML_BUILD=$(cd $HTML_BUILD && pwd)
112
113# Get repo static
114cp -pr $FQ_DOCS_SOURCE/* $FQ_HTML_BUILD
Dean Troyer9b973672013-10-16 15:13:56 -0500115
116# Build list of scripts to process
117FILES=""
118for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
119 echo $f
120 FILES+="$f "
Dean Troyer54b97322014-06-20 17:53:55 -0500121 mkdir -p $FQ_HTML_BUILD/`dirname $f`;
122 $SHOCCO $f > $FQ_HTML_BUILD/$f.html
Dean Troyer9b973672013-10-16 15:13:56 -0500123done
Dean Troyer54b97322014-06-20 17:53:55 -0500124for f in $(find functions functions-common lib samples -type f -name \*); do
Dean Troyer9b973672013-10-16 15:13:56 -0500125 echo $f
126 FILES+="$f "
Dean Troyer54b97322014-06-20 17:53:55 -0500127 mkdir -p $FQ_HTML_BUILD/`dirname $f`;
128 $SHOCCO $f > $FQ_HTML_BUILD/$f.html
Dean Troyer9b973672013-10-16 15:13:56 -0500129done
Dean Troyer54b97322014-06-20 17:53:55 -0500130echo "$FILES" >docs/files
Dean Troyer9b973672013-10-16 15:13:56 -0500131
Dean Troyer54b97322014-06-20 17:53:55 -0500132if [[ -n $GH_UPDATE ]]; then
133 GH_ROOT=$(mktemp -d work-gh-XXXX)
134 cd $GH_ROOT
Dean Troyer9b973672013-10-16 15:13:56 -0500135
Dean Troyer54b97322014-06-20 17:53:55 -0500136 # Pull the latest docs branch from devstack.org repo
137 git clone -b gh-pages $GH_PAGES_REPO gh-docs
Dean Troyer9b973672013-10-16 15:13:56 -0500138
Dean Troyer54b97322014-06-20 17:53:55 -0500139 # Get the generated files
140 cp -pr $FQ_HTML_BUILD/* gh-docs
141
142 # Collect the new generated pages
143 (cd gh-docs; find . -name \*.html -print0 | xargs -0 git add)
144
145 # Push our changes back up to the docs branch
146 if ! git diff-index HEAD --quiet; then
147 git commit -a -m "Update script docs"
148 if [[ -n $PUSH ]]; then
149 git push
150 fi
Dean Troyer9b973672013-10-16 15:13:56 -0500151 fi
152fi
153
154# Clean up or report the temp workspace
155if [[ -n REPO && -n $PUSH_REPO ]]; then
Dean Troyer54b97322014-06-20 17:53:55 -0500156 echo rm -rf $TMP_ROOT
Dean Troyer9b973672013-10-16 15:13:56 -0500157else
158 if [[ -z "$TMP_ROOT" ]]; then
159 TMP_ROOT="$(pwd)"
160 fi
Dean Troyer54b97322014-06-20 17:53:55 -0500161 echo "Built docs in $HTML_BUILD"
Dean Troyer9b973672013-10-16 15:13:56 -0500162fi