blob: 8dca524f9f89d4dcdfa8d6256aa544ece0e0a8d0 [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
103rm -rf docs || true
104git clone -b gh-pages $GH_PAGES_REPO docs
105
106# Build list of scripts to process
107FILES=""
108for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
109 echo $f
110 FILES+="$f "
111 mkdir -p docs/`dirname $f`;
112 $SHOCCO $f > docs/$f.html
113done
114for f in $(find functions lib samples -type f -name \*); do
115 echo $f
116 FILES+="$f "
117 mkdir -p docs/`dirname $f`;
118 $SHOCCO $f > docs/$f.html
119done
120echo "$FILES" >docs-files
121
122# Switch to the gh_pages repo
123cd docs
124
125# Collect the new generated pages
126find . -name \*.html -print0 | xargs -0 git add
127
128# Push our changes back up to the docs branch
129if ! git diff-index HEAD --quiet; then
130 git commit -a -m "Update script docs"
131 if [[ -n $PUSH ]]; then
132 git push
133 fi
134fi
135
136# Clean up or report the temp workspace
137if [[ -n REPO && -n $PUSH_REPO ]]; then
138 rm -rf $TMP_ROOT
139else
140 if [[ -z "$TMP_ROOT" ]]; then
141 TMP_ROOT="$(pwd)"
142 fi
143 echo "Built docs in $TMP_ROOT"
144fi