blob: c566e6356f59599e43bc0f81e84c7540ae5aa90e [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#
5# - Install shocco if not found on PATH
6# - Clone MASTER_REPO branch MASTER_BRANCH
7# - Re-creates ``docs`` directory from existing repo + new generated script docs
8
9# Usage:
10## build_docs.sh [[-b branch] [-p] repo] | .
11## -b branch The DevStack branch to check out (default is master; ignored if
12## repo is not specified)
13## -p Push the resulting docs tree to the source repo; fatal error if
14## repo is not specified
15## repo The DevStack repository to clone (default is DevStack github repo)
16## If a repo is not supplied use the current directory
17## (assumed to be a DevStack checkout) as the source.
18## . Use the current repo and branch (do not use with -p to
19## prevent stray files in the workspace being added tot he docs)
20
21# Defaults
22# --------
23
24# Source repo/branch for DevStack
25MASTER_REPO=${MASTER_REPO:-https://github.com/openstack-dev/devstack.git}
26MASTER_BRANCH=${MASTER_BRANCH:-master}
27
28# http://devstack.org is a GitHub gh-pages site in the https://github.com/cloudbuilders/devtack.git repo
29GH_PAGES_REPO=git@github.com:cloudbuilders/devstack.git
30
Dean Troyerc04ddbe2013-11-06 02:15:11 -060031# Keep track of the devstack directory
32TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
33
Dean Troyer9b973672013-10-16 15:13:56 -050034# Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
35SHOCCO=${SHOCCO:-shocco}
36if ! which shocco; then
Dean Troyerc04ddbe2013-11-06 02:15:11 -060037 if [[ ! -x $TOP_DIR/shocco/shocco ]]; then
Dean Troyer9b973672013-10-16 15:13:56 -050038 if [[ -z "$INSTALL_SHOCCO" ]]; then
39 echo "shocco not found in \$PATH, please set environment variable SHOCCO"
40 exit 1
41 fi
42 echo "Installing local copy of shocco"
Dean Troyerc04ddbe2013-11-06 02:15:11 -060043 if ! which pygmentize; then
44 sudo pip install Pygments
45 fi
46 if ! which rst2html.py; then
47 sudo pip install docutils
48 fi
Dean Troyer9b973672013-10-16 15:13:56 -050049 git clone -b rst_support https://github.com/dtroyer/shocco shocco
50 cd shocco
51 ./configure
52 make
53 cd ..
54 fi
Dean Troyerc04ddbe2013-11-06 02:15:11 -060055 SHOCCO=$TOP_DIR/shocco/shocco
Dean Troyer9b973672013-10-16 15:13:56 -050056fi
57
58# Process command-line args
59while getopts b:p c; do
60 case $c in
61 b) MASTER_BRANCH=$OPTARG
62 ;;
63 p) PUSH_REPO=1
64 ;;
65 esac
66done
67shift `expr $OPTIND - 1`
68
69# Sanity check the args
70if [[ "$1" == "." ]]; then
71 REPO=""
72 if [[ -n $PUSH_REPO ]]; then
73 echo "Push not allowed from an active workspace"
74 unset PUSH_REPO
75 fi
76else
77 if [[ -z "$1" ]]; then
78 REPO=$MASTER_REPO
79 else
80 REPO=$1
81 fi
82fi
83
84# Check out a specific DevStack branch
85if [[ -n $REPO ]]; then
86 # Make a workspace
87 TMP_ROOT=$(mktemp -d devstack-docs-XXXX)
88 echo "Building docs in $TMP_ROOT"
89 cd $TMP_ROOT
90
91 # Get the master branch
92 git clone $REPO devstack
93 cd devstack
94 git checkout $MASTER_BRANCH
95fi
96
97# Processing
98# ----------
99
100# Assumption is we are now in the DevStack repo workspace to be processed
101
102# Pull the latest docs branch from devstack.org repo
Adam Spiers4b2c5ed2013-10-24 17:40:13 +0100103if ! [ -d docs ]; then
104 git clone -b gh-pages $GH_PAGES_REPO docs
105fi
Dean Troyer9b973672013-10-16 15:13:56 -0500106
107# Build list of scripts to process
108FILES=""
109for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
110 echo $f
111 FILES+="$f "
112 mkdir -p docs/`dirname $f`;
113 $SHOCCO $f > docs/$f.html
114done
115for f in $(find functions lib samples -type f -name \*); do
116 echo $f
117 FILES+="$f "
118 mkdir -p docs/`dirname $f`;
119 $SHOCCO $f > docs/$f.html
120done
121echo "$FILES" >docs-files
122
123# Switch to the gh_pages repo
124cd docs
125
126# Collect the new generated pages
127find . -name \*.html -print0 | xargs -0 git add
128
129# Push our changes back up to the docs branch
130if ! git diff-index HEAD --quiet; then
131 git commit -a -m "Update script docs"
132 if [[ -n $PUSH ]]; then
133 git push
134 fi
135fi
136
137# Clean up or report the temp workspace
138if [[ -n REPO && -n $PUSH_REPO ]]; then
139 rm -rf $TMP_ROOT
140else
141 if [[ -z "$TMP_ROOT" ]]; then
142 TMP_ROOT="$(pwd)"
143 fi
144 echo "Built docs in $TMP_ROOT"
145fi